Search code examples
rubyubunturubygemsubuntu-18.04ruby-2.6

Installing Ruby 2.6 on Ubuntu 18.04 - bundler path error


I've installed Ruby 2.6.6 on Ubuntu 18.04 using the following commands:

wget http://ftp.ruby-lang.org/pub/ruby/2.6/ruby-2.6.6.tar.gz
tar -xzvf ruby-2.6.6.tar.gz
cd ruby-2.6.6/
./configure
sudo make install

ruby -v confirms 2.6.6 installed.

But then when I run gem install bundler I get the error /usr/bin/gem: no such file or directory

Before installing Ruby 2.6.6 I removed version 2.5 using sudo apt-get purge ruby, so I'm wondering if the paths need re-configuring. I'm new to Ruby so I'm a bit lost. Any guidance please?

which ruby returns /usr/local/bin/ruby

I've found the gem directory in /usr/local/bin/gem how do I re-configure the gem path reference from /usr/bin/gem to /usr/local/bin/gem?


Solution

  • My first though would be that the path for gem is cached (as it seems like /usr/local/bin is in your PATH). Try to restart the shell and check this for more details: https://unix.stackexchange.com/questions/5609/how-do-i-clear-bashs-cache-of-paths-to-executables

    However, I think you should install Ruby (and in general any other software) from your distro repositories. Otherwise you won't get updates and your package manager may override/break the software later on (as the package manager is unaware of the changes). To do this for Ruby:

    sudo apt install ruby-full
    

    It seems like this will install Ruby 2.5.1. Check packages.ubuntu for details.

    In case you need to install a different Ruby version (for example 2.6), I recommend you to use Rbenv + ruby-build. Check the following guide for more details about how to install Ruby in Ubuntu: https://linuxize.com/post/how-to-install-ruby-on-ubuntu-18-04