How to Install Ruby on Ubuntu

28/12/2020
Chưa phân loại

Ruby is an open-source, dynamic, object-oriented, balanced programming language which is developed by Yukihiro “Matz” Matsumoto in Japan. It is implemented by merging the features of some others popular programming languages, such as PERL, Smalltalk, Ada etc. It has made a balance between functional programming with imperative programming. It is one of the most popular programming language now because it is designed to simplify the programming tasks but not based on machine requirements. It reduces most complex parts of the programming and the programmer can quickly build something from scratch without writing more codes. It is mainly designed for the beginner but anyone can use this language to create any complex application.

So, both novice and experienced programmers can use this language for programming. It is free of charge, so you can easily copy, use, modify and distribute this language without any restriction. Another important feature of ruby is mark-and-sweep garbage collection system. The programmer can write any code in ruby without maintaining the references of extension libraries for this feature. So, when you install Ruby in any supported operating system then ruby will dynamically load extension libraries.

You can install ruby in Linux operating system in various ways. Using apt package manager is the easiest way to install Ruby on Ubuntu operating system. How you can install ruby from command line and run ruby code on Ubuntu are shown in this tutorial.

Installing Ruby

Press Ctrl+Alt+T to open the terminal. Before running the command for installing ruby, you have to update your system. If the system is not updated then ruby will not install properly. Run the following command to update the system.

$ sudo apt-get update

Now, run the following simple command with root permission to install ruby.

$ sudo aptget install rubyfull

Press “y” when it will ask for permission to complete the installation process.

If the installation completes successfully then check ruby is working properly or not. Run the following command. It will show ruby version which is installed in the system. The output shows that ruby version 2.3.3 is installed in the system.

Creating First Ruby Program

You can use any text editor to write ruby script. Here, nano editor is used. The extension for ruby file is rb. Suppose, you have to create a ruby file named first.rb. Then, run the following command from the terminal to open the editor.

$ nano first.rb

Simple input and output operations are shown in the following script. gets command is used in ruby to take input from the user and puts command is used in ruby to print output in the console. In ruby, + operator is used to combine string values.   In the following code, one input will be taken from the user in the variable name and print the value of name after adding other string.

Write the code in the editor.  Press Ctrl + X  and type y to save the file.

puts "Type your name :"
name = gets.chomp
puts "Welcome to LinuxHint " + name

Running Ruby Program

Run the following command from the terminal to run first.rb. If the script is error free then first it will print the message, “Enter your name”, Type something and press enter. It will then print the value that you have typed by adding the string “Welcome to LinuxHint”.

$ ruby first.rb

If you are new in programming, you can choose Ruby language as your first choice to learn programming. By following above simple way, you can easily install ruby in your Ubuntu operating system and start to learn programming or develop any application using ruby script.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Hack Facebook using Social Engineering

I love hacking humans. There is a sense of art to operating in the realm of mind tricking. If you are a magician, you may...
28/12/2020

Best YouTube Apps for Linux

If you don’t like to use the official YouTube website and looking for some alternative ways to stream Youtube videos,...
29/12/2020

Proxy và VPN: Sự khác biệt và ứng dụng của chúng

Khi bạn cần sử dụng proxy để truy cập vào các trang web bị chặn hoặc giới hạn về địa chỉ...
27/02/2023
Bài Viết

Bài Viết Mới Cập Nhật

VPS treo game là gì? Thuê VPS treo game giá rẻ, không lo giật lag
02/06/2025

 BitBrowser – Best Anti-Detect Browser!
26/05/2025

Dịch Vụ Xây Dựng Hệ Thống Peering Với Internet Exchange (IXP)
04/04/2025

Dịch Vụ Triển Khai VPN Site-to-Site & Remote Access
04/04/2025

Dịch Vụ Thiết Lập Hệ Thống Tường Lửa (Firewall)
04/04/2025