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

How Do Rest APIs Work

REST or RESTful APIs are everywhere these days. You may have used it even without knowing anything about it.  In this...
Chưa phân loại, vps giá rẻ
29/12/2020

TCP Wrappers : chúng là gì và chúng được sử dụng như thế nào trong Linux

TCP Wrapper là gì? Đây là một phương pháp chặn truy cập các dịch vụ trên máy chủ Linux của bạn...
30/12/2020

How to SSH into your VirtualBox Guest

There are times when you want to have a remote access to your VM. Maybe, it’s just a server operating system running...