How can I upgrade my Ruby Gems to the latest version "safely"? - ruby

Is there any way that I can upgrade my Ruby Gems, and if it doesn't work (on what I'm upgrading them for), than rollback the changes?

You need install rubygems in other directory of your previous version. After you can change all link to rubygems to this new version.
You can use too rvm. It's really simple and it's allways with latest rubygems. If you don't want it. just delete the .rvm directory.

Just upgrade RubyGems as normal, if it messes up, just download the last version and run sudo ruby setup.rb. http://rubygems.org/pages/download
If you do run into problems, the RubyGems team would love to hear about it: http://help.rubygems.org

Related

RVM, where is Ruby 3.0.0?

I want to download the latest Ruby release(version 3.0.0), using RVM but I am faced with the following error when running rvm install 3.0.0:
Unknown ruby interpreter version (do not know how to handle): 3.0.0
I have also tried 3 & 3.0, but gives the same error.
According to this page, it should be available through RVM. I'm already using RVM to manage my ruby versions, so I don't want to use rbenv ... nor do I want to install from source.
How can I get Ruby version 3.0.0 installed using RVM?
If you have not updated rvm do that first RVM Upgrading
rvm get stable
# or
rvm get master # for even newer versions not in stable 3.0.0 in this case
To see all available rubies run
rvm list remote all
# or
rvm list known # as pointed out in the comments
you should see ruby-3.0.0 in the list of available rubies
Then run
rvm install ruby-3.0.0
In many parts of the world, the current time is holiday time. RVM is maintained by unpaid volunteers in their spare time, who might choose to spend time with their families.
Therefore, it might take a while for a new release of RVM to come out.
Also, there are a couple of bugs related to YARV 3.0.0 not working on the RVM bug tracker, obviously those will need to be fixed before a new release of RVM that supports YARV 3.0.0 can be released.
According to the RVM offline installation docs, the required extension to install any Ruby version is .tar.bz2.
Taking a look at the Ruby's 3 FTP folder, the .tar.bz2 is available only for the preview1 release. Neither the rc1 nor the official has that extension available yet.
I think we gotta wait for some maintainer to update the FTP folder with that extension.
First you need to upgrade the RVM. Then try to install the needed version again ->
rvm get master && rvm install 3.0.0
You can just rename the .tar.gz file to be a .tar.bz2 and everything will work. Here's the steps:
As stated in previous answers, update rvm to the latest stable version with:
rvm get stable
Download the release 3.0.0 gz file from: https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.0.tar.gz
Move the downloaded file into your .rvm/archives folder and rename it to a .bz2 in the process:
mv ~/Downloads/ruby-3.0.0.tar.gz ~/.rvm/archives/ruby-3.0.0.tar.bz2
Make sure you've got at least gcc v8 installed, or newer. This is required due to the multi-threaded concurrency features of Ruby 3. I used gcc-10, which on my Mac I had installed with Homebrew. If you do use a newer version of gcc then you'll need to set the CC environment variable:
export CC=gcc-10
With everything now in place, install as usual, which will automatically find the appropriate .bz2 file in your archives folder:
rvm install ruby-3.0.0

How to upgrade from ruby 2.2.3 to ruby 2.3.0

My current Ruby version is 2.2.3 and I want to upgrade it to 2.3.0.
I use rbenv using this guide: gorails.com/setup/ubuntu/16.04
How do I upgrade my Ruby version? And when I upgrade, does it affect anything that I need to be aware of?
This answer had been written to address the original question, which did not specify rbenv as a preferred approach. Although the question changed after this answer was written, the answer has been retained to help users that may be using RVM to upgrade/manage their Ruby installations.
See the rbenv answer for details on using rbenv for the same purpose.
Use RVM or another Ruby version manager. This is far superior to installing a new system Ruby in most cases.
If you're upgrading your system Ruby, you have a number of things to keep in mind:
what other dependencies are there on that Ruby version?
are all of the gems going to be available after upgrade?
which applications are using the existing Ruby version and what can/will break after upgrade?
are there any other users using the existing Ruby that need to be aware of (and prepare for) the change?
With a Ruby version manager, you eliminate most of these concerns. You can run multiple Ruby versions on the same machine, which gives you the ability to test backward and forward compatibility. It also lets you experiment with the newer Ruby versions to make sure that they're fully stable for use.
You can install RVM using this method from any bash shell:
\curl -sSL https://get.rvm.io | bash -s stable
or update it to the most recent stable version by using:
rvm get stable
Once RVM is installed (or updated), you can install any Ruby version you choose, by doing the following:
rvm install 2.3.0
or upgrade from one version to another:
rvm upgrade 2.2.3 2.3.0
You can see which Ruby versions are installed by using this:
rvm list
You can also check to see which versions of Ruby that you can install on RVM by using this command:
rvm list known
Switch to a specific installed Ruby version by using the use command:
rvm use 2.3.0
and then switch back to an older version when you need to:
rvm use 2.2.3
Check out the RVM documentation for more features. You'll be surprised at how useful RVM actually is. There's a whole lot more to it than just what's shown here.
To upgrade your Ruby version using rbenv, you can use these steps. Some will only be necessary based on your environment. Plugins are an important aspect of this, if you have any installed.
Update rbenbv
First, you'll want to make sure that your rbenv version is updated. If you have the update plugin installed, you can update rbenv and all installed plugins using a single command:
rbenv update
Using the update plugin is highly recommended. However, if you are not using the update plugin, you can manually update rbenv in this way:
cd ~/.rbenv
git pull
Update plugins
If you have manually updated rbenv, you'll also need to update the plugins manually, as well. Make sure to follow the update instructions for each plugin.
One plugin that's very important to update at this point (if you have it installed) is the ruby-build plugin, which provides build support for Ruby under rbenv. This may improve the experience installing a new Ruby version in the next step.
Install Ruby version
After you have updated rbenv, you can install the new Ruby version:
rbenv install -v 2.3.0
Remove Ruby version
rbenv will allow you to manage and use multiple Ruby versions on a single machine. This is a huge benefit. However, if you no longer want the older Ruby version installed, you can remove it like this:
rbenv uninstall 2.2.3
Note that you can always re-install the Ruby version after uninstalling it, and use rbenv to manage the versions separately. This is good practice when working with multiple projects.

reinstall every gem for each ruby version?

I just installed Ruby 2.0.0 using rbenv and set it to the global ruby version for my system. Since 2.0 is compatible with 1.9.3, I tried to start up a Rails project with it, but got the following error. I did rbenv rehash after installing 2.0
The `rails' command exists in these Ruby versions:
1.9.3-p327
Does this mean that every gem I installed on my system with 1.9.3 has to be reinstalled if I wish to use it with 2.0?
As seen here:
You need to reinstall bundler for each version of Ruby you use. See Ruby versions where you have it installed:
rbenv whence bundle
See your current version:
rbenv version
Install bundler for that version, if missing:
gem install bundler
Yes. Rbenv (and RVM) have separate "gem home" directories for each installed version of Ruby. There may be ways to symlink certain directories to get them to share, but this will likely lead to problems, particularly with gems that include native C extensions, which may or may not compile and run cleanly in multiple versions.
If you have a Gemfile, easiest thing is to just bundle install again for Ruby 2.0, giving you duplicate copies of many gems and Ruby-2.0 compiled versions of any native gems.
Another solution to this is to copy (or reinstall) the gems from your previous version to the newly installed version. How to do that is answered in detail in this question, which has two scripts -- one to install from local cache, one to reinstall from the internet (mine).

How can I manage rubygems version with bundler?

I just started learning Ruby, and for my sandbox I use latest Rubygems version, according to examples and tutorials.
At the same time I have Redmine, which requires Rubygems 1.6.2.
To manage gem versions I use bundler, but can I use it to manage Rubygems version too?
I dont think so - I believe it uses your current rubygem from the environment.
However you can use rvm to manage the rubygems version, so if you install it and have a project specific gemset in your .rvmrc file.
I think rvm is OSX/unix only - there is an alternative for Windows I believe.

Specifying location of gems

I've done some searching online and tried a few things with no luck.
I compiled Ruby 1.9.1 on a Mac that had previously been running 1.8.7.
How can I now either reinstall the gems, or point. Rubygems installs to the old location, but 1.9.1 is looking elsewhere. I've tried making a 1.9.1 (and 1.9) gems directory as a symlink to the old directory, but that doesn't seem to work. I've tried setting GEM_HOME and GEM_PATH but again no luck.
How can I find out where the current version of ruby is searching for gems at runtime, and alter it? And/or, how can I instruct rubygems to install gems where the latest version is looking for the gems.
You should either use a rvm, as was suggested, or install ruby 1.9.2 to /opt/ruby (configure --prefix=/opt/ruby --enable-shared) or /usr/local or /usr/local/ruby. Then put this path first in your PATH, before everything else. You'll have to reinstall gems anyway, as some of them are incompatible (built for 1.8.7).
It would be a good idea to install rvm and let it wrangle your Ruby versions and gems for you.
Also, you should probably upgrade to 1.9.2, as it's much more stable. 1.9.1 is basically a buggy development version of 1.9.2.

Resources