We hope this post helped you to find out “How to Install Ruby on Ubuntu 20.04”
Ruby is without doubt one of the hottest programming languages in the present day. It has a chic syntax and focuses on simplicity and productiveness. Ruby is the language behind the highly effective Ruby on Rails framework.
On this tutorial we’ll present you three other ways to put in Ruby on Ubuntu 20.04:
- From the usual Ubuntu repositories. That is the best solution to set up Ruby on Ubuntu and needs to be enough for many use instances. The model included within the Ubuntu repositories is
- Utilizing Rbenv. A script that lets you have a number of Ruby variations put in on the identical machine.
- Utilizing RVM (ruby enVironment supervisor). A heavier and extra feature-packed script that lets you set up, handle, and work with a number of ruby variations.
Select the set up methodology that’s applicable on your atmosphere. If you’re creating Ruby purposes and work a number of Ruby environments, then the popular approach is to put in Ruby utilizing Rbenv or RVM.
If you’re undecided which Ruby model to put in, seek the advice of the documentation of the appliance you’re going to deploy.
Installing in Ruby from Ubuntu Repositories #
The best solution to set up Ruby on Ubuntu is by utilizing the
apt bundle supervisor. On the time of writing, the model within the Ubuntu repositories is
2.7.0, which can not all the time be the most recent secure launch.
The set up is fairly easy. Run the next instructions as root or person with sudo privileges to replace the bundle index and set up Ruby:
sudo apt update
sudo apt install ruby-full
Once completed, verify the installation by printing the Ruby version:
The output will look something like this:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
Your Ruby model might differ from the one proven above.
That’s it! You’ve got efficiently put in Ruby in your Ubuntu machine, and you can begin utilizing it.
Installing in Ruby utilizing Rbenv #
Rbenv is a light-weight command-line device that lets you simply swap Ruby variations.
By default, rbenv doesn’t deal with putting in Ruby. We’ll use
ruby-build to put in Ruby. It’s out there as a standalone program and as a plugin for rbenv.
ruby-build script installs Ruby from the supply. To have the ability to construct Ruby, set up the required libraries and compilers:
sudo apt update
sudo apt install git curl autoconf bison build-essential
libssl-dev libyaml-dev libreadline6-dev zlib1g-dev
libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev
The only solution to set up the rbenv device is to make use of the set up shell script. Run the next
curl or to obtain and execute the script:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-installer | bash
The installer script also calls another script that verifies the installation. The output of the script will look something like below:
Running doctor script to verify installation... Checking for `rbenv' in PATH: not found You seem to have rbenv installed in `/home/vagrant/.rbenv/bin', but that directory is not present in PATH. Please add it to PATH by configuring your `~/.bashrc', `~/.zshrc', or `~/.config/fish/config.fish'.
To start using rbenv, you need to add
$HOME/.rbenv/bin to your
- If you are using Bash:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
- If you are using Zsh:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
rbenv -v command to ensure that installation was successful:
To get a list of all Ruby versions that can be installed with
rbenv install -l
For example, to install Ruby version 2.7.1 and set it as a global version, you would type:
rbenv install 2.7.1
rbenv global 2.7.1
Rbenv works by inserting a listing named shims on the entrance of your
PATH. This listing incorporates scripts (shims) whose job is to intercept Ruby instructions and execute the corresponding binaries.
Rbenv lets you set shell, native and world Ruby model:
- The shell model is used within the present shell, and has the very best precedence. It may be outlined by setting the
RBENV_VERSIONatmosphere variable utilizing the
rbenv shell <ruby-version>command.
- The native model is about on a per-directory foundation. This model is written within the
.ruby-versionfile. Once you run a Ruby script, rbenv searches for the file within the present and all mother or father directories. It makes use of the Ruby model saved within the first discovered file. To set a neighborhood model, navigate to the listing and run
rbenv native <ruby-version>command.
- The worldwide model is utilized in all shells when no shell or native model is about. Use
rbenv world <ruby-version>to set a worldwide model.
Don’t use sudo to put in gems when Ruby is managed with rbenv. Every Ruby model is put in within the
~/.rbenv/variations listing and writeable by the person.
Putting in Ruby utilizing RVM #
RVM is a command-line device that you should use to put in, handle, and work with a number of Ruby environments.
Set up the dependencies required to construct Ruby from supply:
sudo apt update
sudo apt install curl g++ gcc autoconf automake bison libc6-dev
libffi-dev libgdbm-dev libncurses5-dev libsqlite3-dev libtool
libyaml-dev make pkg-config sqlite3 zlib1g-dev libgmp-dev
Run the following commands to add the GPG key and install RVM:
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
To start using RVM, load the script environment variables using the
To get a list of all Ruby versions that can be installed with this tool, type:
rvm list known
Install the latest stable version of Ruby with RVM and set it as the default version:
rvm install ruby
rvm --default use ruby
Verify that Ruby was properly installed by printing the version number:
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux]
If you want to install a specific version of Ruby, enter the commands below. Replace
x.x.x with the Ruby version you want to install:
rvm install ruby-x.x.x
rvm --default use ruby-x.x.x
To switch to another version without setting it as your default Ruby, enter:
rvm use ruby-x.x.x
For extra details about how you can handle your Ruby installations with RVM examine their Documentation page.
We have now proven you three other ways to put in Ruby on Ubuntu 20.04. The strategy you select is determined by your necessities and preferences. Although putting in the packaged model from the Ubuntu repository is simpler, the Rbenv and RVM scripts provide you with extra flexibility to make use of totally different Ruby variations on a per person foundation.
We hope the “How to Install Ruby on Ubuntu 20.04” help you. If you have any query regarding “How to Install Ruby on Ubuntu 20.04” drop a comment below and we will get back to you at the earliest.
We hope this post helped you to find out “How to Install Ruby on Ubuntu 20.04” . You may also want to see – How to Install PostgreSQL on Ubuntu 20.04