How to install ruby on ubuntu

How to install ruby on ubuntu

How to Install Ruby 3 on Ubuntu 20.04

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Ruby is an open-source, object-oriented, and general-purpose programming language which is one of the most popular programming languages. Ruby programming language is the reason behind the powerful Ruby and Rails framework.

There are multiple ruby managers available to install Ruby. Ruby managers allow to use multiple versions and help to switch between ruby versions. The most commonly used ruby managers are rbenv and rvm. Ruby is also available in the Ubuntu repository.

In this article we will be learning three different ways to install Ruby 3 on Ubuntu 20.04.

Pre-Requisites

Method 1- Install Ruby Using Rbenv

Many Rubyists in the community prefer installing ruby using rbenv. Rbenv is a tool that can be used to switch between different versions of Ruby. However, this tool can not be used to install Ruby.

To install Ruby, you will need another tool ruby-build. Use the following command to update Ubuntu 20.04 repository to the latest index.

Run the following command to install dependencies.

After installing dependencies, run the following command to clone both Rbenv and Ruby-build repositories at Github.

Now you can install any available version of Ruby using Rbenv. Run the following command to list available versions.

You will get the output as:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntuListing Available Ruby versions

You can install the version you want by running the following command. For this article, I am installing Ruby 3.0.0.

This will take a few minutes to complete.

To set the global variable run the following command:

Replace the version number with your environment-compatible version.

To verify the installed Ruby version, run the following command:

You will get output similar as:

Method 2- Installing Ruby from Ubuntu Repositories

The simplest and easiest way to install Ruby is using Ubuntu’s built-in apt package manager. The Ruby version installed using the default apt package manager is usually the latest one.

Run the following command to update ubuntu repositories to latest index.

Use following command to install Ruby.

After completing installation, run the following command to verify if Ruby is installed:

You will get the output similar as:

The output verifies the installation of Ruby version 3.0.0

Another tool for installing and managing Ruby on Ubuntu and other Linux system is RVM.

Update the Ubuntu Repositories to latest index using following command:

To install RVM dependencies, run the following command:

Now run the following command to install RVM:

Run the following command to activate RVM:

Now you can install Ruby using following command:

You can replace version number with your compatible version

To use installed Ruby as default, run the following command:

To verify your installation, run the following command:

You will get output in your screen similar as:

From the output the installed Ruby version is 3.0.0

Conclusion

In this article, you learned different methods to install Ruby 3 on Ubuntu 20.04. Also, you learned how to verify your Ruby installation and how to install different versions compatible with your environment.

How To Install Ruby on Ubuntu 18.04

Home » DevOps and Development » How To Install Ruby on Ubuntu 18.04

Ruby is a dynamic, open-source programming language behind the Ruby on Rails framework. It is especially appealing to beginners because of its highly readable and clear syntax, allowing users to develop fast and efficiently.

In this guide, find three options to install Ruby on Ubuntu 18.04 – either from the Ubuntu repository or from third-party tools (RVM and rbenv).

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Option 1: Install Ruby from the Ubuntu Repository

To install Ruby from the default Ubuntu repositories, follow these steps:

1. Open the terminal either by using Ctrl+Alt+T keyboard shortcut. Or, by running a search in Ubuntu Dash and typing in the word “terminal and selecting the Terminal Icon as seen in the image below.

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

2. Make sure to update the package repository cache to ensure you install the latest versions of the software.

To do so, type in the following command:

3. Start the Ruby installation process by running the command:

Press y and hit Enter to verify the installation.

4. To check whether the installation was successful, type in the command:

The output you receive will show you which version of Ruby you have installed, just like in the image below:

As you can see, we have installed Ruby version 2.5.1.

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Option 2: Installing Ruby with RVM

Ruby Version Manager (RVM) is a command-line tool which allows you to easily install, manage and work with Ruby versions and their gems.

To enable RVM, you will have to install the GPG keys to verify the installation package.

Step 1: Install GPG

1. Start by running the command:

2. Next, install the keys:

Step 2: Install RVM

1. Before installing RVM, you will need to install software prerequisites with the command:

2. Next, you will add the PPA repository for Ubuntu and finally install RVM.

3. At this point, it is recommended to restart your system.

Step 3: Install Ruby

Now that you have set up the RVM command-line, you can install Ruby by typing the following command:

2.5.1 is one version of Ruby. You can specify whichever version of Ruby you want to install.

Make sure the installation was successful by checking the version of Ruby you have installed with the command:

Note: If you are running a Windows server, you can refer to How to Install Ruby on Windows 10.

Option 3: Install Ruby Using rbenv

Simple Ruby Version Management (rbenv) is a third-party command tool designed for easier alternation between various Ruby versions. It is specific to switching Ruby versions, making it simple and predictable.

1. Copy the command below to install the packages and dependencies required to build Ruby:

2. To install rbenv and ruby-build, type in the command:

3. Next, you need to add rbenv to your path with the following three (3) commands:

4. After you have installed rbenv, you can install the latest version of Ruby. Run the command:

5. Make sure the installation was successful by checking the version of Ruby you have installed:

Update Ruby Gems Package Manager

To install, manage and distribute your Ruby libraries (also called gems) you will need the RubyGems package manager.

Each gem contains a Ruby code which you can share with other users. Primarily, these gems serve as libraries from which you can easily install any package required.

The RubyGems management framework is part of Ruby which is why you don’t have to install it separately.

However, you may need to update to the latest version with the command:

Note: There are several ways to install Ruby on an Ubuntu system. To find out more, refer to How to install Ruby on Ubuntu 20.04.

By following one of the three methods above, you will successfully install Ruby on Ubuntu 18.04.

Next, you may want to install a full Ruby on Rails stack. This is one of the most popular application-development stacks in use. Rails is a development framework for the Ruby programming language that simplifies and speeds up app development.

Installing Ruby

With package managers or third-party tools, you have plenty of options to install and manage Ruby.

You may already have Ruby installed on your computer. You can check inside a terminal emulator by typing:

This should output some information on the installed Ruby version.

Choose Your Installation Method

There are several ways to install Ruby:

On Windows 10, you can also use the Windows Subsystem for Linux to install one of the supported Linux distributions and use any of the installation methods available on that system.

Here are available installation methods:

Package Management Systems

If you cannot compile your own Ruby, and you do not want to use a third-party tool, you can use your system’s package manager to install Ruby.

Some members of the Ruby community feel that you should avoid package managers to install Ruby and that you should use dedicated tools instead.

It is possible that major package managers will install older Ruby versions instead of the latest release. To use the latest Ruby release, check that the package name matches its version number. Or use a dedicated installer.

apt (Debian or Ubuntu)

Debian GNU/Linux and Ubuntu use the apt package manager. You can use it like this:

yum (CentOS, Fedora, or RHEL)

CentOS, Fedora, and RHEL use the yum package manager. You can use it like this:

The installed version is typically the latest version of Ruby available at the release time of the specific distribution version.

snap (Ubuntu or other Linux distributions)

Snap is a package manager developed by Canonical. It is available out-of-the-box on Ubuntu, but snap also works on many other Linux distributions. You can use it like this:

We have several channels per Ruby minor series. For instance, the following commands switch to Ruby 2.3:

portage (Gentoo)

Gentoo uses the portage package manager.

pacman (Arch Linux)

Arch Linux uses a package manager named pacman. To get Ruby, just do this:

This should install the latest stable Ruby version.

Homebrew (macOS)

Ruby versions 2.0 and above are included by default in macOS releases since at least El Capitan (10.11).

Homebrew is a commonly used package manager on macOS. Installing Ruby using Homebrew is easy:

This should install the latest Ruby version.

FreeBSD

FreeBSD offers both pre-packaged and source-based methods to install Ruby. Prebuilt packages can be installed via the pkg tool:

A source-based method can be used to install Ruby using the Ports Collection. This is useful if you want to customize the build configuration options.

More information about Ruby and its surrounding ecosystem on FreeBSD can be found on the FreeBSD Ruby Project website.

OpenBSD

OpenBSD as well as its distribution adJ has packages for the three major versions of Ruby. The following command allows you to see the available versions and to install one:

The HEAD branch of the OpenBSD ports collection might have the most recent version of Ruby for this platform some days after it is released, see directory lang/ruby in the most recent ports collection.

Ruby on OpenIndiana

To install Ruby on OpenIndiana, please use the Image Packaging System (IPS) client. This will install the Ruby binaries and RubyGems directly from the OpenIndiana repositories. It’s easy:

However, the third-party tools might be a good way to obtain the latest version of Ruby.

Windows Package Manager

On Windows, you can use the Windows Package Manager CLI to install Ruby:

Chocolatey package manager for Windows

Also on Windows, you can use the Chocolatey Package Manager to install Ruby:

Other Distributions

On other systems, you can search the package repository of your Linux distribution’s manager for Ruby. Alternatively, you can use a third-party installer.

Installers

If the version of Ruby provided by your system or package manager is out of date, a newer one can be installed using a third-party installer.

Some installers allow you to install multiple versions on the same system; associated managers can help to switch between the different Rubies.

If you are planning to use RVM as a version manager you don’t need a separate installer, it comes with its own.

ruby-build

ruby-build is a plugin for rbenv that allows you to compile and install different versions of Ruby. ruby-build can also be used as a standalone program without rbenv. It is available for macOS, Linux, and other UNIX-like operating systems.

ruby-install

ruby-install allows you to compile and install different versions of Ruby into arbitrary directories. chruby is a complimentary tool used to switch between Ruby versions. It is available for macOS, Linux, and other UNIX-like operating systems.

RubyInstaller

On Windows, RubyInstaller gives you everything you need to set up a full Ruby development environment.

Just download it, run it, and you are done!

Ruby Stack

If you are installing Ruby in order to use Ruby on Rails, you can use the following installer:

Managers

Many Rubyists use Ruby managers to manage multiple Rubies. They allow easy or even automatic switching between Ruby versions depending on the project and other advantages but are not officially supported. You can however find support within their respective communities.

asdf-vm

asdf-vm is an extendable version manager that can manage multiple language runtime versions on a per-project basis. You will need the asdf-ruby plugin (which in turn uses ruby-build) to install Ruby.

chruby

chruby allows you to switch between multiple Rubies. It can manage Rubies installed by ruby-install or even built from source.

rbenv

rbenv allows you to manage multiple installations of Ruby. While it can’t install Ruby by default, its ruby-build plugin can. Both tools are available for macOS, Linux, or other UNIX-like operating systems.

RVM (“Ruby Version Manager”)

RVM allows you to install and manage multiple installations of Ruby on your system. It can also manage different gemsets. It is available for macOS, Linux, or other UNIX-like operating systems.

Uru is a lightweight, multi-platform command line tool that helps you to use multiple Rubies on macOS, Linux, or Windows systems.

Building from Source

Of course, you can install Ruby from source. Download and unpack a tarball, then just do this:

You can find more information about building from source in the Ruby README file.

Using the third-party tools or package managers might be a better idea, though, because the installed Ruby won’t be managed by any tools.

3 Ways to Install Ruby on Ubuntu 22.04

This article will provide you with different methods to install Ruby on Ubuntu 22.04.

How to Install Ruby on Ubuntu 22.04

There are three methods to install Ruby on Ubuntu 22.04 which are as following:

Method 1: Using Rbnev

Rbnev is a command-line utility that allows you to install the latest version of Ruby on Ubuntu 22.04. It also allows you to run multiple Ruby versions side-by-side.

The following steps are required to install Ruby on Ubuntu 22.04 successfully.

Step 1: First update the Ubuntu apt package system using the following command:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 2: Next, install required dependencies and libraries for Ruby using the following command:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 3: Next, run the shell script file using the below-mentioned command:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 4: To start using Rbnev, you will need to update the path environment using the following shell script command:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 5: Once Rbnev installation is completed, you can then list the Ruby version using the following command.

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 6: Now, use the following command to install the latest version of Ruby on Ubuntu:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 7: To set the installed version of Ruby as a global, execute the following command:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

To confirm the latest Ruby version, use the following command.

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Method 2 : Using Ruby Version Manager

You can also install Ruby through the built-in Ruby Version Manager (RVM). To perform the installation through this method, use the following steps.

Step 1: Update packages using the following command:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 2: Install required dependencies with the following command-line.

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 3: Now, install RVM by executing the below-given command:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 4: Next, execute the following command to find out the available version on RVM:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

As 3.1.2 is the latest version, so execute the following installation command to install the latest version of Ruby on Ubuntu:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

The above command will successfully install Ruby on Ubuntu and you can begin creating different applications with ease by implementing code in Ruby language.

Method 3: Using Ubuntu 22.04 repository

Ubuntu 22.04 repository also includes the Ruby which you can easily install using the following steps. However, it doesn’t install the latest version but still it’s the easiest method to install Ruby on Ubuntu.

Step 1: Update the apt package system using the following command:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 2: Then use the below-mentioned command to install Ruby on Ubuntu:

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Step 3: After the Ruby installation is completed, you can then check the version using the following command.

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Removing Ruby from Ubuntu 22.04 repository

To remove Ruby from Ubuntu 22.04 repository, execute the below-mentioned command.

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Conclusion

Ruby is an open-source and robust programming language used to develop different web applications. There are several methods to install Ruby on Ubuntu 22.04 mentioned in this article. If you want to install the latest version of Ruby, you can pick the Rbnev or RVM method and to ease the installation, you can install Ruby through the apt command.

About the author

How to install ruby on ubuntu. Смотреть фото How to install ruby on ubuntu. Смотреть картинку How to install ruby on ubuntu. Картинка про How to install ruby on ubuntu. Фото How to install ruby on ubuntu

Awais Khan

I’m an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.

Установка Ruby

Вы можете использовать различные инструменты для установки Ruby. Эта страница описывает, как использовать основные системы управления пакетами и сторонние инструменты для управления и установки Ruby, и как собрать Ruby из исходников.

Выберите ваш метод установки

Есть несколько способов установки Ruby:

В следующем списке перечислены доступные способы установки для различных нужд и платформ.

Системы управления пакетами

Если вы не можете скомпилировать ваш собственный Ruby и не хотите использовать сторонний инструмент для установки – вы можете воспользоваться пакетным менеджером вашей операционной системы.

Некоторые участники сообщества Ruby убеждены, что никогда не стоит пользоваться пакетными менеджерами для установки Ruby. Вместо этого лучше воспользоваться другими инструментами. Оставим все плюсы и минусы данного подхода за границами данного текста, отметим лишь, что основной причиной данной убежденности является то, что в пакетных менеджерах зачастую содержится информация об устаревших версиях Ruby. Если вы хотите использовать новейшую версию Ruby, убедитесь, что вы используете верное имя пакета или воспользуйтесь инструментами описанными ниже вместо этого.

apt (Debian или Ubuntu)

Пакет ruby-full установит Ruby версии 2.3.1, которая является последним стабильным релизом.

yum (CentOS, Fedora, или RHEL)

Устанавливаемая версия обычно является последней версией Ruby, доступной на момент выхода конкретной версии дистрибутива.

portage (Gentoo)

pacman (Arch Linux)

Это должно установить последнюю стабильную версию Ruby.

Homebrew (macOS)

На OS X El Capitan, Yosemite и Mavericks, Ruby 2.0 уже включены. OS X Mountain Lion, Lion и Snow Leopard поставляются с версией Ruby 1.8.7.

Многие люди на macOS используют Homebrew как пакетный менеджер. И это действительно просто – установить Ruby:

Это установит последнюю версию Ruby.

OpenBSD

OpenBSD, а также его дистрибутив adJ, имеет пакеты для трех основных версий Ruby. Следующая команда позволяет вам увидеть доступные версии и установить одну из них:

Ветка HEAD коллекции портов OpenBSD может иметь самую последнюю версию Ruby для этой платформы через несколько дней после ее релиза, смотрите директорию lang/ruby в самой последней коллекции портов.

Ruby на Solaris и OpenIndiana

Ruby 1.8.7 доступен для Solaris 8-10 на Sunfreeware и Blastwave. Ruby 1.9.2p0 также доступен на Sunfreeware, но это все уже устарело.

Чтобы установить Ruby на OpenIndiana, пожалуйста, используйте клиент Image Packaging System, или IPS. Это установит последние бинарники Ruby и RubyGems прямо из сетевого репозитория OpenSolaris для Ruby 1.9. Это просто:

Однако, сторонние инструменты могут быть хорошим способом получить последнюю версию Ruby.

Другие дистрибутивы

На других системах, вы можете поискать репозиторий пакета Ruby для пакетного менеджера вашего Linux дистрибутива, или же сторонние инструменты могут стать хорошим выбором для вас.

Установщики

ruby-build

ruby-install

ruby-install позволяет вам скомпилировать и установить различные версии Ruby в произвольные каталоги. Существует также родственник chruby, который управляет переключением между версиями Ruby. Он доступен для macOS, Linux и других UNIX-подобных операционных систем.

RubyInstaller

Для пользователей Windows существует отличный проект, помогающий установить Ruby: RubyInstaller. Он предоставляет вам все, что нужно для настройки полноценного окружения Ruby на Windows.

Просто скачайте его, запустите и все готово!

Ruby Stack

Если вы устанавливаете Ruby для того, чтобы воспользоваться Ruby on Rails, вы можете использовать следующий установщик:

Менеджеры

Многие рубисты используют менеджеры для управления несколькими версиями Ruby. Они предоставляют различные преимущества, но поддерживаются не официально. Однако их сообщество может оказать помощь.

asdf-vm

chruby

chruby позволяет вам переключаться между разными версиями Ruby. chruby может управлять версиями Ruby, которые установлены с помощью ruby-install или даже собранными из исходников.

rbenv

rbenv позволяет вам управлять несколькими установленными версиями Ruby. Он не поддерживает установку Ruby, но для этого существует популярный плагин ruby-build. Оба инструмента доступны для macOS, Linux и других UNIX-подобных операционных систем.

RVM (“Ruby Version Manager”)

RVM позволяет вам устанавливать и управлять несколькими установленными версиями Ruby в вашей системе. Также он может управлять разными наборами гемов. Доступен для macOS, Linux и других UNIX-подобных операционных систем.

Сборка из исходников

Конечно, вы можете установить Ruby из исходников. Скачайте и распакуйте архив, затем просто выполните:

Использование сторонних инструментов или пакетных менеджеров может быть лучше, хотя бы потому, что установленные Ruby не будут управляться любыми инструментами.

Источники информации:

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *