What is Ruby on Rails?
Ruby on Rails is one of the most popular application stacks for developers looking to create sites and web apps. The Ruby programming language, combined with the Rails development framework, makes app development simple.
Installation
Step 1 – Install rbenv and Dependencies
Ruby relies on several packages which you can install through your package manager. Once those are installed, you can install rbenv and use it to install Ruby,
First, update your package list:
sudo apt update
Next, install the dependencies required to install Ruby:
sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
Once the dependencies download, you can install rbenv itself. Clone the rbenv repository from GitHub into the directory ~/.rbenv:
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
If you recieve an error on the git
command follow my tutorial on how to install Git on Ubuntu by clicking here.
Next, add ~/.rbenv/bin to your $PATH so that you can use the rbenv command line utility. Do this by altering your ~/.bashrc file so that it affects future login sessions:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
Then add the command eval "$(rbenv init -)" to your ~/.bashrc file so rbenv loads automatically:
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Next, apply the changes you made to your ~/.bashrc file to your current shell session:
source ~/.bashrc
Verify that rbenv is set up properly by using the type command, which will display more information about the rbenv command:
Your terminal window will show the following output.
rbenv is a function rbenv () { local command; command="${1:-}"; if [ "$#" -gt 0 ]; then shift; fi; case "$command" in rehash | shell) eval "$(rbenv "sh-$command" "$@")" ;; *) command rbenv "$command" "$@" ;; esac }
Next, install the ruby-build, plugin. This plugin adds therbenv install command, which simplifies the installation process for new versions of Ruby:
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
At this point, you have both rbenv and ruby-build installed. Let’s install Ruby next.
## Step 2 – Installing Ruby with ruby-build
With the `ruby-build` plugin now installed, you can install versions of Ruby y may need through a simple command. First, let’s list all the available versions of Ruby:
rbenv install -l
The output of that command should be a long list of versions that you can choose to install.
Let’s install Ruby 2.5.1
:
rbenv install 2.5.1
Installing Ruby can be a lengthy process, so be prepared for the installation to take some time to complete.
Once it’s done installing, set it as our default version of Ruby with the global sub-command:
rbenv global 2.5.1
Verify that Ruby was properly installed by checking its version number:
ruby -v
If you installed version 2.5.1
of Ruby, your output to the above command should look something like this:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
That’s it, you have successfully installed Ruby on Rails
on your Ubuntu Device and you can start using it!