How to get a current Ruby version without messing up your system
Do not mess with your system Ruby, but instead install a current version with either rbenv
or RVM. I prefer the first, but both work fine. Note that you can only install one of those at a time.
With such a Ruby version manager, you'll never have to type sudo
again to install (or uninstall) a Gem, and you can keep different versions for different projects. You can safely remove these versions again.
Please make sure to read the README
s of those tools, at least once.
Method 1 – rbenv
rbenv is a version manager for Ruby. It allows you to install a Ruby version alongside your original system Ruby, which means you cannot mess up that one, and you can easily upgrade versions.
To install it, use the rbenv-installer
. Make sure to restart your shell once it's installed, and that the rbenv
function works.
Then, once rbenv is installed, run rbenv install -l
. This gives you a list of available Rubies. Install your chosen one with:
rbenv install 2.5.1
Now choose this one as your default:
rbenv global 2.5.1
As soon as this is done, gem
can be used to run:
gem install rails
If the above does not work, you might be missing required packages for building from source. See here for a list of packages that you might want to install. On Ubuntu, these include:
sudo apt install autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm5 libgdbm-dev
Method 2 – RVM
You can also install Ruby over RVM. Here as well, you don't need to sudo
anything, and you'll be able to get more recent versions of Ruby alongside the system one.
Read the installation instructions for your system.
After installation, you can install Rubies with a simple command. First, check rvm list known
to get the list of installable versions. Now install your choice:
rvm install 2.5.1
Then, set it as the default Ruby version for your user:
rvm use 2.5.1 --default
Now you can install Rails over gem
:
gem install rails
What happens if you do "which ruby", does it show as being installed? Does "ruby -v" show the right version number? – Nathaniel Bannister – 2011-06-01T20:10:18.207
Install: sudo apt-get install ruby1.9.1-full ruby -v – BILL – 2011-06-01T20:13:12.573
Program 'ruby' is not installed. – BILL – 2011-06-01T20:13:22.853
When you type "sudo apt-get install ruby1.9.1-full" in a terminal does anything happen? – slotishtype – 2011-06-01T20:24:41.570
1
I'm a little confused by your update. If you want to install rails please use RVM - http://rvm.beginrescueend.com/ - to install rails and any other gems. It is a package manager and will save you a lot of time.
– slotishtype – 2011-06-01T21:10:29.690