How do I make Ruby 1.9 the default Ruby on Ubuntu? - ruby

Is there any way, on Ubuntu 9.04, to install Ruby 1.8 as ruby1.8 (or get rid of it altogether) and have Ruby 1.9 be the default ruby?

I'm not really sure, but maybe this can help:
update-alternatives --config ruby
... and here's the non-interactive, scriptable, way:
update-alternatives --set ruby /usr/bin/ruby1.9.1
You may find out about available alternatives and respective /usr/bin/... paths by doing:
update-alternatives --query ruby

Martin - Take a look at the following link: http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/
This is where installation of ruby is heading for ubuntu servers. This should allow you to not only switch to a ruby version when needed, but also keep gems separated based on ruby versions, etc.

You can completely remove Ruby 1.8 too with:
sudo apt-get remove libruby1.8 ruby1.8 ruby1.8-dev rubygems1.8
After that, you will only have Ruby 1.9 installed.

sudo \curl -L https://get.rvm.io | bash -s stable --ruby --rails
will install an up-to-date version of ruby (and rails), and allow you to avoid brokenness of Ubuntu's RVM, see https://stackoverflow.com/a/9056395/497756.
If you go this route, get rid of Ubuntu-installed versions and associated packages like bundle.
Details here: https://rvm.io/rvm/install/
(Note: this is the TL;DR version of the post by henry74.)

Try this:
sudo apt-get install ruby1.9.1 rubygems1.9.1
or try building from source. this worked for me on ubuntu 9.04 and after a restart 1.9 was the standard ruby

Related

'sudo ruby setup.rb' won't install Gems on Vagrant box

I'm new to using Vagrant and am trying to install Gems on it (Ruby is already installed). I am following the instructions here.
I've downloaded the latest version of Gems and extracted it. I have "cd'd" into that folder and have tried to run:
ruby setup.rb
But get a Permission denied error, so I try sudo:
sudo ruby setup.rb
But this gives me the error:
sudo: ruby: command not found
Would anyone know what's going on here?
Edit - more info
I checked the version of ruby and its 2.3.0p0.
If I try to check the version of Gems is says to install Ruby 1.9.1.
I don't really understand this...
sudo doesn't preserve your $PATH environment variable, so unless ruby is installed somewhere that's in root's path, it's not going to be found.
Run which ruby to find out where ruby is installed, then sudo /path/to/ruby setup.rb
Also, more importantly, that's completely unnecessary. Those instructions are old. Rubygems has been built-in to ruby for a long time now. The site you linked even says, "If you’re on Ruby 1.9.*, then you don’t have to worry about installing Rubygems; it’s built in." If you're on 2.3.0, you don't need to install Rubygems, you have it already.
I suggest to you use RMV to install Ruby and Gem versions.
Install RVM
https://rvm.io/
- gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
- \curl -sSL https://get.rvm.io | bash -s stable
- source /home/vagrant/.rvm/scripts/rvm
Install Ruby
rvm get stable --autolibs=enable
rvm install ruby-2.3.1
Use default ruby version
rvm --default use ruby-2.3.1

How do I tell the system to treat one of the ruby-build rubies as the system ruby?

I don't have any ruby installed on my linux mint by apt-get. Instead, I installed ruby using ruby-build. I now have ruby installation in
/opt/rubies/ruby-2.0.0-p0/
How do I make this ruby installation the 'system' ruby just like apt-get sets ruby executable during apt-get install ruby1.9.1 for example.
I want to register this version as system ruby and when I use rubies switching with chruby (or rvm or rbenv) I want that to be seen as system ruby?
Do I simply use update-alternatives? Do I reinstall ruby from source with make? Any other suggestions please.
You can add the path to your custom ruby build in the $PATH environment variable.
export PATH="/my-build-path/bin:$PATH"
(or something like that)
If you want a system Ruby, use ruby-build to install the Ruby into /usr/local:
$ ruby-build 2.0.0-p0 /usr/local/
If I had previously installed ruby with
sudo apt-get install ruby
then the apt process sets up alternatives so I have an entry for ruby group
/usr/bin/ruby -> /etc/alternatives/ruby
Now I can simply add my own ruby installation to the ruby group
$ sudo update-alternatives --install /usr/bin/ruby ruby /opt/rubies/ruby-2.0.0-p0/bin/ruby 1
and either set or config alternative to point to the ruby I want
$ sudo update-alternatives --set ruby /opt/rubies/ruby-2.0.0-p0/bin/ruby
# or sudo update-alternatives --config ruby
# and select the entry I want
The above I can do only after I have original alternatives set by apt-get during ruby install.
However If I DO NOT have ruby installed with apt-get then I can use the same mechanism even if I don't have /etc/alternatives/ruby in place yet.
I just do the following
$ sudo update-alternatives --install /usr/bin/ruby ruby /opt/rubies/ruby-2.0.0-p0/bin/ruby 1
additionally I may want to add gem as well.
What I am not sure about is how does that affect the gems installed

why my ruby version is still an old version on ubuntu after I installed ruby1.9.2?

I am newbie to ubuntu and ROR. After installed latest ruby1.9.2 with apt-get, type "ruby -v" it still shows up old version ruby1.8.7. I tried to reinstall with rvm, nothing changed.
As mentioned in similar question, I tried to remove ruby, and reinstall ruby1.9.1-full... still the same thing...
What else I can do about this?
ubuntu uses a something called alternatives for chosing between two version of similar executable. Running
sudo update-alternatives --config ruby
and chosing the ruby you want should do the trick
I'm using RVM myself, but if I remember correctly, ruby1.8 and ruby1.9 can be installed side by side on Ubuntu. ruby is just a symbolic link which points to version 1.8 by default - which should be called ruby1.8 and stored in the same directory. 1.9 will be called ruby1.9.
So just find where ruby symbolic link is (whereis ruby) and change it so it points to ruby1.9.
sudo rm /path/ruby
sudo ln -s /path/ruby1.9 /path/ruby
Sounds like you are using rvm, but still referencing system ruby. To switch, you have to tell rvm what version to use.
rvm use 1.9.2
This will switch your current environment only. So ruby -v in your current shell will use the right version. (you should probably go with 1.9.3, FWIW) If you want to always use that ruby be default, you type:
rvm use 1.9.2 --default
If you want to switch back to system ruby, you can use:
rvm use system
I think it is because the package of Ruby version at apt-get repository is an old version.
I suggest use rbenv to install the latest version.
Here is a great tutorial using rbenv to install the latest Ruby version from Digital Ocean:
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04
sudo apt-get install ruby1.9
should do the trick.
You can find what libraries are available to install by
apt-cache search <your search term>
So I just did apt-cache search ruby | grep 9 to find it.
You'll probably need to invoke the new Ruby as ruby1.9, because Ubuntu will probably default to 1.8 if you just type ruby.

Ruby on Mac OSX via Mac Ports

I'm new to both Ruby and to Mac OSX, though I do have a fair amount of experience with Unix commands. I just installed Ruby 1.9 via a MacPorts command (port install ruby19). I then needed to do a find from root just to figure out where it went, which turned out to be: /opt/local/var/macports/software/ruby19/1.9.1-p376_0/opt/local/bin/ruby1.9.
The current version of Ruby (1.8.6) runs via /usr/bin/ruby, which is a symbolic link to /System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby where Current is a symbolic link to a directory called 1.8.
I'd like to make Ruby 1.9 my default (along with related tools like irb), and while I can manage to do that, I'd like to know if there's a conventional way. Should I copy or link the MacPorts path to /System/Library/Frameworks/Ruby.framework/Versions/1.9 and then point Current to 1.9? (I'd also have rename or copy the executables: ruby1.9 to ruby, irb1.9 to irb, etc.) Or should I just blow away the /usr/bin/ruby link (and /usr/bin/irb, etc) and create new ones pointing to the MacPorts version?
You can easy to use port select command, under MacPorts 2.1.3
$sudo port select --set ruby ruby19
Install the nosuffix variant instead:
sudo port install ruby19 +nosuffix
Your newer ruby version should now take precedence over the preinstalled one.
My advice:
$ port uninstall ruby1.9
Then follow this: https://rvm.io/rvm/install/
Then:
$ rvm install 1.9.2
$ rvm --default 1.9.2
You might even rvm install macruby to toy with Cocoa.
In the lastest version of macports (2.1.3 or greater) you can use the port select command.
port select --list ruby
sudo port select --set ruby ruby19
For earlier versions of macports you can make a symbolic link to the numbered ruby version. This is the way that macports generally handles switching between different versions of packages.
cd /opt/local/bin
sudo ln -s ruby1.9 ruby
I would highly recommend RVM. It takes a bit of reading, but once you have it installed you can install a ruby with rvm install 1.9 (or jruby, ree, 1.8, etc), and switch between them with rvm 1.9. Each ruby version will also have its own, completely isolated set of rubygems.
The ruby1.9 binary should be installed in /opt/local/bin; if it's not, you may not have activated the port.
The easiest way to make Ruby 1.9 the default root is to create an alias for ruby to ruby1.9. If you're using Bash, you can do that by putting this in your Bash config file:
alias ruby='/opt/local/bin/ruby1.9'
Uninstall ruby version 1.8:
sudo port uninstall ruby
Install ruby version 1.9:
sudo port install ruby19
Reopen terminal

Installing Ruby 1.9.1 on Ubuntu?

I wonder about installing the latest version of Ruby on Ubuntu 9.04. Now I can run through the ./configure and make stuff fine, but what I wonder about: how to avoid conflicts with the packaging system? For example if some other package I install depends on Ruby, wouldn't the package manager install the (outdated) Ruby package and in the worst case overwrite my files?
So I think I need some way to tell Ubuntu that Ruby is in fact already installed?
Save yourself the headache and use RVM (Ruby Version Manager)
Keep in mind, Rails 3 works best with Ruby 1.9.2. Ruby 1.9.2 fixes up quite a few bugs in 1.9.1 and is preferable to running 1.9.1.
With RVM installing 1.9.2 is a breeze.
sudo apt-get install ruby1.9.1-full
(http://www.ruby-lang.org/en/downloads/)
After running
sudo apt-get install ruby1.9.1-full
It's solution is to run the following command:
sudo update-alternatives --config ruby
Then you will get this output:
There are 2 choices for the alternative ruby (providing /usr/bin/ruby).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/ruby1.8 50 auto mode
1 /usr/bin/ruby1.8 50 manual mode
2 /usr/bin/ruby1.9.1 10 manual mode
Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/ruby1.9.1 to provide /usr/bin/ruby (ruby) in manual mode.
$ ruby --version
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
Credit for this solution goes to person who answered https://askubuntu.com/questions/91693/how-do-you-uninstall-ruby-1-8-7-and-install-ruby-1-9-2 . Currently the ruby1.9.1 package is actually ruby 1.9.2.
The way I did it was to build it using checkinstall which lets you build a deb package. So I downloaded the Ruby 1.9.1 source, did a "configure" and then "make", did a "checkinstall" and made the package name ruby1.9 so it installs as if it were a new version of ruby 1.9 (as it should).
I got the Ruby specific info from this site.
You can install most software in a different directory with the --prefix=/path switch. And it is common to install in /opt/ for everyone on your pc, or in $HOME if it is only for you.
For installing in /opt:
$ ./configure –prefix=/opt/ruby
$ make install
If you want to use the /opt installed ruby, edit you ~/.bashrc and add
export PATH=/opt/ruby/bin/:$PATH
If you don't want to have the custom Ruby build as default, you can add this to your ~/.bashrc instead of the former command
function setupruby {
export PATH=/opt/ruby/bin/:$PATH
}
Here is a short and convenient way to install 1.9.1 and to make it default:
http://michalf.me/blog:make-ruby-1-9-default-on-ubuntu-9-10-karmic-koala
I created a launchpad ppa for ruby 1.9.2. Details in the links below
http://www.humbug.in/2010/launchpad-ppa-for-ruby-1-9-2-and-some-ruby-bindings/
sudo add-apt-repository ppa:pratikmsinha/ruby192+bindings
cd /etc/apt/sources.list.d/; sudo mv pratikmsinha-ruby192+bindings-lucid.list pratikmsinha-ruby192bindings-lucid.list
sudo aptitude update
sudo aptitude install ruby1.9.2
Looking through Synaptic it seems like you don't even have to deal with the Multiverse or third-party repositories. But since sudo apt-get install ruby currently installs an alias to ruby1.8, you should install ruby1.9 explicitly – manually or via the repositories – and create the alias ruby yourself.
You may want to put the binary in /usr/bin since that's where the distribution would put it anyway. Anywhere on your PATH is fine, though.

Resources