101.rbenv
Install Ruby on Rails with rbenv
Ubuntu prerequisites
Update and install dependencies in ubuntu
sudo apt-get update
sudo apt-get install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
Install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
From here, you should add ~/.rbenv/bin
to your $PATH
so that you can use rbenv’s command line utility. Also adding ~/.rbenv/bin/rbenv init
to your ~/.bash_profile
will let you load rbenv automatically.
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
Next, source rbenv by typing:
source ~/.bashrc
You can check to see if rbenv was set up properly by using the type command, which will display more information about rbenv:
type rbenv
Your terminal window should output the following:
rbenv is a function
...
In order to use the rbenv install
command, which simplifies the installation process for new versions of Ruby, you should install ruby-build, which we will install as a plugin for rbenv through git:
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
Arch Linux
yaourt -S rbenv ruby-build
At this point, you should have both rbenv and ruby-build installed, and we can move on to installing Ruby.
Install Ruby
With the ruby-build rbenv plugin now installed, we can install whatever versions of Ruby that we 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.
We’ll now install a particular version of Ruby. It’s important to keep in mind that installing Ruby can be a lengthy process, so be prepared for the installation to take some time to complete.
As an example here, let’s install Ruby version 2.3.1, and once it’s done installing, we can set it as our default version with the global sub-command:
rbenv install 2.5.1
rbenv global 2.5.1 # for a global install
rbenv local 2.5.1 # for a project install
If you would like to install and use a different version, simply run the rbenv commands with a different version number, as in rbenv install 2.3.0 and rbenv global 2.3.0.
Verify that Ruby was properly installed by checking your version number:
ruby -v
If you installed version 2.3.1 of Ruby, your output to the above command should look something like this:
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]
You now have at least one version of Ruby installed and have set your default Ruby version. Next, we will set up gems and Rails.
Working with Gems
Gems are packages that extend the functionality of Ruby. We will want to install Rails through the gem command.
So that the process of installing Rails is less lengthy, we will turn off local documentation for each gem we install. We will also install the bundler gem to manage application dependencies:
echo "gem: --no-document" > ~/.gemrc
gem install bundler
Update rbenv
cd ~/.rbenv
git pull
cd plugins/ruby-build
git pull
Related posts by tag
- 07 Nov 2024 daisyUI — Tailwind CSS Components
- 04 Mar 2024 Using personal gems with Bundle without bothering your colleagues.
- 12 Jul 2023 Protomaps - A serverless system for planet-scale maps