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

Bash ‘mkdir’ not existent path

‘mkdir’ is the basic built-in shell command of Linux to create a new directory or folder from the terminal. You can...
29/12/2020

Emacs Org Mode, Part 1

How to use emacs Org-mode to plan your life? What is org-mode Emacs was designed as an editor when development started...
29/12/2020

Thuê proxy nuôi zalo là gì? Top 3 cách chọn đúng proxy tốt nhất

Thuê proxy nuôi zalo là một biện pháp cần thiết để bạn có thể bảo vệ cũng như sử dụng tài...
02/10/2023
Bài Viết

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

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?
27/05/2024