How to Install Version Specified Ruby Using Apt

How to install version specified Ruby using apt

The specific version of ruby you want to install has to be a package available in your Ubuntu distro's package repository. A quick way to check this is using apt list | grep ruby-full or apt list | grep ruby.

If you don't find the version you're looking for, you can add a repository and download it from there. Brightbox is a widely used repository maintaining several ruby version packages. Their installation docs should help you.

Note: I still recommend that you use a ruby version manager like rbenv or rvm.

How to install version specified Ruby in ubuntu

You can install rbenv which is a Ruby Environment and then you can install the version of Ruby you want over it.

Refer to this answer

How to install Ruby 2.1.4 on Ubuntu 14.04

First of all, install the prerequisite libraries:

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev

Then install rbenv, which is used to install Ruby:

cd
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install 2.3.1
rbenv global 2.3.1
ruby -v

Then (optional) tell Rubygems to not install local documentation:

echo "gem: --no-ri --no-rdoc" > ~/.gemrc

Credits: https://gorails.com/setup/ubuntu/14.10

Warning!!!
There are issues with Gnome-Shell. See comment below.

installed ruby using apt-get install ruby 2.0.0 succeeded but not using correct ruby version

If you're new to linux I'd recommend using something like RVM (Ruby Version Manager) to install ruby. It makes it easier to switch ruby versions and manage multiple gemsets.

To install RVM with the latest (stable) ruby:

\curl -L https://get.rvm.io | bash -s stable --ruby

then check which rubies are installed by using

rvm list

you can then switch ruby versions using

rvm use 2.0.0 --default

with the --default flag overriding any system ruby.

Update
If you really don't want to use RVM, then use

sudo apt-get install checkinstall

wget -c http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz
tar -xzf ruby-2.0.0-p0.tar.gz
cd ruby-2.0.0-p0

./configure
make

sudo checkinstall -y \
--pkgversion 2.0.0-p0 \
--provides "ruby-interpreter"

checkinstall will package the source, making it easier to remove in the future

You'll then need to add the Ruby binaries to your path, by editing the env file:

sudo nano /etc/environment

add /usr/local/ruby/bin

PATH="/usr/local/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

then run

source /etc/environment

to reload the file, and check your ruby version with

ruby -v

How to install ruby on linux in a specific folder

It sounds like what you want is Ruby's source code. Go to https://www.ruby-lang.org/en/downloads/ and look under "Compiling Ruby - Source Code". That's where you'll find the .tar.gz files you want. You'll need to compile and install it before you can actually use it. Installing normally copies files "all over the file system", but you can force it to install to a specific folder by passing the --prefix option to the ./configure script.

$ tar -xf ruby-2.2.1.tar.gz
$ cd ruby-2.2.1
$ ./configure --prefix=/my/ruby/dir
$ make && make install

You may need to install some dev packages in order to get it to compile, but any compilation errors should make it clear what you need.

These instructions are also described here.

Ruby: How to install a specific version of a ruby gem?

Use the -v flag:

$ gem install fog -v 1.8

How to change ruby version

There is lots of advise in the comments to your question, some of it is advanced-ish rbenv or rvm usage.

My advice: Decide on how to manage multiple rubies - either use your OS package manager (in your case the apt-get/PPA stuff) OR rvm OR rbenv.

For the OS package manager, there should be a way to call ruby with version explicitely (e.g. /usr/bin/ruby1.9.3), or research on and call update-alternative. As bundler comes with a gem, you might get the interpreters confused here.

For rvm, change ruby version with rvm use 2.5.1 (once it is installed).

For rbenv I actually do not know but it should be trivial, too (and people are happy with it; it just happens that I tried rvm first and it worked like a charm, never evaluated rbenv).

I usually install one "system" ruby (apt-get install ruby1.9.3) and use rvm afterwards. You can still switch to the packaged "production" ruby with rvm use system.

Update 2017: Most distros ship with a ruby version installed already, so you probably don't have to install it manually. Run ruby -v or which ruby to see if a ruby interpreter is already installed.

In your case I would probably deinstall all system rubys (apt-get purge ...), remove the PPAs, remove your ~/.rvm and rbenv and start from scratch (install packaged stable ruby, then rvm and use rvm (r.g. rvm install 2.3.1) from there on).

How do I install the latest version of ruby in Ubuntu?

I use Ubuntu, and I've found the easiest way to install newer versions of Ruby is to use rvm.

The instructions are here: https://rvm.io/rvm/install/

Basically, it installs different versions of Ruby locally for the user and updates environment variables for Ruby and gems based on which version you decide to use.

It's this easy:

jim@schubert:~$ rvm use system
Now using system ruby.
jim@schubert:~$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
jim@schubert:~$ gem -v
1.3.7
jim@schubert:~$ rvm use 1.9.2
Using /home/jim/.rvm/gems/ruby-1.9.2-p180
jim@schubert:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
jim@schubert:~$ gem -v
1.5.2
jim@schubert:~$


Related Topics



Leave a reply



Submit