How to change ruby version on linux - ruby

I installed rvm on my Linux machine and download simple project from github. I tried to run rails s, but got a error with ruby version:
I executed next commands:
rvm install ruby-2.3.0
rvm use ruby-2.3.0
rvm use ruby-2.3.0 --default
When I opened the project and ran rails s, I got this error
https://i.imgur.com/Dwvp8WF.png
Update
My Gemfile has ruby 2.3.0
Can't run bundle install because of this error https://imgur.com/a/UMcirdt
w
which rails, which ruby: https://imgur.com/a/vycG8wG

I haven't used rvm, but I'm using rbenv for version management.
From what I've read, it works similarly, although the commands are a little bit different.
Did command rvm use ruby-2.3.0 inside the project folder generate a file called .ruby_version?
It should list the current version of ruby used in this project

After checked the errors on your updated screenshot, I think it's better just do this:
rm -r ~/.bundle
bundle
bundle install
Maybe just
rvm reinstall all
then try again.
If permission error happens, run
rvm fix-permissions
And then do it again.

Related

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user)

below is what I need to do.
To run the specs, you'll need to install RSpec. First, run gem install bundler in the root directory of your project. Then, run bundle install. To run a single spec file, run a command like this: bundle exec rspec spec/00_hello_spec.rb. To run all of the specs at once, run bundle exec rspec.
So, I typed gem install bundler in Terminal, and got the error:
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
and this was in the project file in atom
source "https://rubygems.org"
gem "rspec", "~> 3.2.0"
My question is:
It seems like terminal is giving me the response because I'm not supposed to change anything on ruby, and I need to bundle install inside of atom? Could anyone tell me how to use atom or run anything in atom?
Update:
I now have a paid script that will set up a proper Ruby environment for you with a single command!
I also keep my free step-by-step guide for installing Ruby on a Mac up to date (more often than I update this answer).
You are correct that macOS won't let you change anything with the Ruby version that comes installed with your Mac. However, it's possible to install gems like bundler using a separate version of Ruby that doesn't interfere with the one provided by Apple.
Using sudo to install gems, or changing permissions of system files and directories is strongly discouraged, even if you know what you are doing. Can we please stop providing this bad advice? I wrote a detailed article that shows why you should never use sudo to install gems.
The solution involves two main steps:
Install a separate version of Ruby that does not interfere with the one that came with your Mac.
Update your PATH such that the location of the new Ruby version is first in the PATH. Some tools do this automatically for you. If you're not familiar with the PATH and how it works, it's one of the basics that you should learn, and you'll understand why you sometimes get "command not found" errors and how to fix them.
There are several ways to install Ruby on a Mac. The best way that I recommend, and that I wish was more prevalent in the various installation instructions out there, is to use an automated script like Ruby on Mac that will set up a proper Ruby environment for you.
The main reason is that it saves each person a ton of time. Time is our most limited and valuable resource. Why make people do things manually when they can be automated with a perfect result every time?
Another reason is that it drastically reduces the chance of human error, or errors due to incomplete instructions.
If you want to do things manually, keep on reading. First, you will want to install Homebrew, which installs the prerequisite command line tools, and makes it easy to install other necessary tools.
Then, the two easiest ways to install a separate version of Ruby are:
If you would like the flexibility of easily switching between many Ruby versions [RECOMMENDED]
Choose one of these four options:
chruby and ruby-install - my personal recommendations and the ones that are automatically installed by the Ruby on Mac script. These can be installed with Homebrew:
brew install chruby ruby-install
rbenv - can be installed with Homebrew
RVM
asdf
If you chose chruby and ruby-install, you can then install the latest Ruby like this:
ruby-install ruby
Once you've installed everything and configured your .zshrc or .bash_profile according to the instructions from the tools above, quit and restart Terminal, then switch to the version of Ruby that you want. In the case of chruby, it would be something like this:
chruby 3.1.3
Whether you need to configure .zshrc or .bash_profile depends on which shell you're using.
If you know for sure you don't need more than one version of Ruby at the same time (besides the one that came with macOS) [NOT RECOMMENDED]
Even if you think you won't need another version now, you will eventually and you won't be able to easily switch. This will cause confusion and headaches, which is why I don't recommend installing and managing Ruby with Homebrew.
If you choose to use Homebrew to install Ruby despite my warnings, you'll be on your own if you run into any issues.
Install ruby with Homebrew:
brew install ruby
Then update your PATH by running this command:
echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.1.0/bin:$PATH"' >> ~/.zshrc
The 3.1.0 in the command above assumes Homebrew installed a Ruby version that starts with 3.1. If it installed a different version, replace 3.1 with the first two digits of your Ruby version.
If you're on an M1/M2 Mac, replace /usr/local with /opt/homebrew
Then "refresh" your shell for these changes to take effect:
source ~/.zshrc
Or you can open a new terminal tab, or quit and restart Terminal.
Replace .zshrc with .bash_profile if you are using Bash. If you're not sure, read my guide to find out which shell you're using.
To check that you're now using the non-system version of Ruby, you can run the following commands:
which ruby
It should not be /usr/bin/ruby
ruby -v
It should be 3.1.3 or later.
Once you have this new version of Ruby installed, you can now install bundler (or any other gem):
gem install bundler
Worked for me using the parameter --user-install running following command:
gem install name_of_gem --user-install
Edit
There was one gem I still could not install (it required the Ruby.h headers of the Ruby development kit or something), then I tried the different version managers, but somehow that still did not really work as it was stated in the documentations how to just install and switch (it did just not switch the versions).
Then I removed all the installed version managers and installed afterwards with brew install ruby the latest version and did set the PATH variable, too. (It will be mentioned after the installation of ruby from brew), which worked.
If you don't want to run sudo then install ruby using homebrew
brew install ruby
export GEM_HOME="$HOME/.gem"
gem install rails
You may want to add export GEM_HOME="$HOME/.gem" to your ~/.bash_profile or .zshrc if you're using zsh
Note: RubyGems keeps old versions of gems, so feel free to do some cleaning after updating:
gem cleanup
Just export GEM_HOME:
export GEM_HOME="$HOME/.gem"
And then try:
gem install cocoapods
As #idleberg mentions, on Mac OS, it is best to install rbenv to avoid permissions errors when using manually installed ruby.
Installation
$ brew update
$ brew install rbenv
Add the following in .bashrc file:
eval "$(rbenv init -)"
Now, we can look at the list of ruby versions available for install
$ rbenv install -l
Install version 2.3.8 for example
$ rbenv install 2.3.8
Now we can use this ruby version globally
$ rbenv global 2.3.8
Finally run
$ rbenv rehash
$ which ruby
/Users/myuser/.rbenv/shims/ruby
$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [x86_64-darwin17]
Go for it
Now install bundler
$ gem install bundler
All done!
It's generally recommended to use a version manager like rbenv or rvm. Otherwise, installed Gems will be available as root for other users.
If you know what you're doing, you can use sudo gem install.
Try this:
sudo gem install cocoapods --user-install
Worked for me
PLEASE USE SUDO WITH CARE!!!!!! ONLY IF YOU KNOW WHAT YOU ARE DOING!!!!!!!!!!!!
I have faced same issue after install macOS Catalina. I had try below command and its working.
sudo gem update
Run this
$ rbenv init
# Load rbenv automatically by appending
# the following to ~/.zshrc:
eval "$(rbenv init -)"
Follow instructions, (in my case add to ~/.zshrc) ;)
Also important: Changes only take effect if you reboot your console. Two options
Enter source <modified file>
close and open again
Try 1 or 2
1 - $ gem install cocoapods
2 - $ sudo gem install cocoapods
if it doesn't work, then export GEM_HOME:
export GEM_HOME="$HOME/.gem"
And try again:
gem install cocoapods
Remember the oficial doc says you can use sudo (https://guides.cocoapods.org/using/getting-started.html#getting-started).
To fix this, I ran
brew reinstall ruby
which showed me this message
==> Caveats
==> ruby
By default, binaries installed by gem will be placed into:
/opt/homebrew/lib/ruby/gems/3.1.0/bin
You may want to add this to your PATH.
ruby is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.profile
So I added these two lines to my ~/.bashrc file
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
export PATH="/opt/homebrew/lib/ruby/gems/3.1.0/bin:$PATH"
Then I opened a new Terminal.app window and ran my gem install command again and it worked.
Tested on M1 MacBook Air (assuming Homebrew installed)
Following to the top answer, we can run:
brew install chruby ruby-install
To install the latest stable ruby:
ruby-install ruby
Then get the version number by running:
chruby
In your ~/.zshrc file:
export PATH=/opt/homebrew/bin:$PATH
source /opt/homebrew/opt/chruby/share/chruby/chruby.sh
source /opt/homebrew/opt/chruby/share/chruby/auto.sh
chruby 3.1.2
The "3.1.2" is the output I got when running chruby. Make sure you add that one line at the end.
Remember to restart the terminal each time you install a new gem.
If you have installed ruby separately and installed ruby using rbenv/rvm you budler might point to different versions.
try
gem env home
and
ruby -v
both should point to same version.check you have installed ruby using rbenv/rvm, If so delete the ruby version you installed separately.
In order for gem to work, you must invoke rbenv,
rbenv shell <ruby version>
and
rbenv global <ruby version>
I am not sure how RVM works.
Let me know if this works.
After install rbenv ,I also have this problem , add this line in my .bashrc :
eval "$(rbenv init -)"
solved my problem.
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.
In my case, the issue was related to ruby access some how the ruby path was messed up in my system.
The below steps helped me resolve the problem
Open the terminal
Install ruby using homebrew
[for fresh install] brew install ruby
[for reinstalling] brew reinstall ruby
Check the path of ruby using the below command
which ruby
It should be installed in the below path
/usr/bin/ruby
To change the ruby path to the user path
To check which shell is used by your system
echo $0
-zsh
For zshrc
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >>~/.zshrc
For bash
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >>~/~/.bashrc
Quit and relaunch the terminal
After changing the path with step 5
Check for the path of the ruby again (execute step 3 - please make sure the path displays as given below)
/usr/local/opt/ruby/bin/ruby
[if you don't quit and launch the terminal, step 4 path will be shown]
This step may not be applicable to everyone can skip step 10 & 11, if you have the correct Cocoapods version installed
Check the version of the pod installed
pod --version
Uninstall the specific version of Cocoapods using the below command
In case the version installed is 1.11.0
gem uninstall cocoapods -v 1.11.0
Install the Cocoapods of the specific version
gem install cocoapods -v 1.11.0
Change the path to the Project directory cd {path of the project directory}
Install the bundler in the project directory
bundle install
Execute pod install
pod install
I deleted those directories by using the below command
sudo rm -rf \
/Library/Ruby/Gems/2.6.0/{build_info,cache,doc,extensions,gems} \
/Library/Ruby/Gems/2.6.0/specifications/*.gemspec \
/Library/Ruby/Site
then installed cocoa pods using sudo gem install cocoapods
and it worked for me. Thanks
TL;DR
In several occasions, I've solved this kind of errors by just closing my terminal session and opening a new one before retrying the failing command.
Long explanation
In some SOs (such as MacOS) there is already a pre-installed, system-wide version of ruby. If you are using a version manager, such as rbenv or asdf, they work by playing with the environment of your current session so that the relevant commands point to the binaries installed by the version manager.
When installing a new binary, the version manager installs it in a special location, usually somewhere under the user's home directory. It then configures everything in your PATH so that you get the freshly installed binaries when you issue a command, instead of the ones that came with your system. However, if you don't restart the session (there are other ways of getting your environment updated, but that's the easiest one) you don't get the new configuration and you will be using the original installation.
Had the same error because I forgot to run the following after installing ruby:
source ~/.zshrc - or other ~/...rc file depending on your terminal
rbenv global 2.6.3 helped me solve this problem.
A different installation of ruby should be used. I use rbenv for that purpose.
# install your version of ruby
$ rbenv install 2.0.0-p247
# modify .ruby_version on current directory
$ rbenv local 2.0.0-p247
# proceed installing gems
$ gem install bundler
Disclamer: I am not a ruby person. This worked for me and if you are a ruby expert and see things to change in this answer, please, go ahead or comment!
I was using the below command to install fastlane but didn't worked
gem install fastlane -NV
So using sudo to install gems worked for me and it would be like
sudo gem install fastlane -NV
I try it, and work to me
export PATH=/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.0.0/bin:$PATH
export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
gem install ffi
For latest OS versions
First run sudo xcode-select --switch /
sudo gem install cocoapods --user-install
this did it for me
for Mac OS 12 and above also for 13
Xcode 14 and above
first you call
export GEM_HOME="$HOME/.gem"
after that
gem install cocoapods
home its help you ☺️
Solution for Mac
Install/update RVM with last ruby version
\curl -sSL https://get.rvm.io | bash -s stable
Install bundler
gem install bundler
after this two commands (sudo) gem install .... started to work
Solution for MAC. run the command
sudo gem update
then type your Mac password when prompted
After trying the previous approaches, this worked for me on Big Sur:
sudo gem install -n /usr/local/bin cocoapods
Install homebrew by passing this into your terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install cocoapods using brew
brew install cocoapods
After install ruby with rbenv you also need to set global ruby. For that you can do like, rbenv global 3.2.1 then install bundler with gem install bundler. It will work.
This worked for me on Mac
sudo chown -R $(whoami) $(brew --prefix)/*

Bundler::GemfileNotFound whenever I try to run bundle install

I'm working in kali-linux (a linux distro witch is the continuation of Back-Track, based in Ubuntu, just that now is based on Debian wheezy) for some penetration testing. Everything was working just fine, until I decided to update my systems tools. Now whenever I try to run a tool based on ruby, it trows me:
Could not find gem 'ruby-progressbar (>= 1.1.0) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
I proceed to run bundle install but then it comes with Bundler::GemfileNotFound error.
Kali use by default ruby, for using gems. The software don't 'require' any other package but ruby seems not-fully-configured/installed for the problem at hand.
$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [i486-linux]
$ rvm
bash: rvm: command not found
$ rbenv
bash: rbenv: command not found
I faced the same problem when I was trying to bundle install without realizing that I was not in the project directory. Make sure you're in the current project directory.
to avoid this error you should be at the root of your application and create GemFile and specify all gems needed in there, and run bundle install
The problem was that for some weird motive Ruby didn't detected that bundler was installed, although the package manager says so.
$ apt-cache policy bundler
bundler:
Installed: 1.3.5-2
Candidate: 1.3.5-2
$ bundle --version
Bundler::GemfileNotFound
I simply run gem install bundler then bundler install as root in the tool root path and everything works as charm.
Do you use rvm or rbenv? If so, make sure you are using a particular ruby version.
For rvm, rvm list and look for an indication next to your ruby version. If the correct one is not listed, run rvm install x.y.z. If the correct one is not selected, run rvm use x.y.z
If you want to segregate your gems for a given project, create a gemset. Otherwise, you should be good to go.
Run gem install bundler. You should not have to do this as sudo. This will install bundler in either the Default rvm gemset, or the selected gemset.
Bundler should now be available and can be run using bundle. This is the same as bundle install.
Try this:
sudo ln -s /var/lib/gems/1.8/bin/bundle /bin/bundle
sudo ln -s /var/lib/gems/1.8/bin/bundler /bin/bundler
Worked for me in debian.

Rubygems on OSX missing

I feel like a compelte idiot, but I've been wrking on this all day and getting no where.
I've restarted several times trying to get a full install of Ruby on my OSX environment, RVM, Brew, Ruby: and every time I get through to the Ruby install it bottoms out on the rubygems install.
The reason I'm having to start again is that the RVM wouldn't update in Jewelerybox after my first successfull install (used a packaged all-in-one RubyInstaller) so I couldn't manage my gems - a problem caused by the initial Ruby install on the system living in the /usr/local and not under my own directory. To fix this I uninstalled all my Ruby stuff and started again.
All ok until the ruby compiler started gacking on the rubygems install section when installing ruby 2.0.0. Checking out the OSX system files under usr/bin I see that rubygems isn't there either (it should be present by default on OSX). Any ideas? (note that XCode is up to date and has command line tools installed)
Last attempt was:
$ rvm get head --autolibs=3 # get the latest RVM and build required libs
$ rvm requirements # just in case, install all other required stuff
$ rvm remove 2.0.0
$ rvm install ruby-2.0.0
. . . which fires the following error:
[2013-03-19 23:21:50] /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/bin/ruby
Exception `LoadError' at /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rubygems.rb:1073 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/rubygems.rb:1082 - cannot load such file -- rubygems/defaults/ruby
mkdir -p /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/site_ruby/2.0.0
...
install -c -m 0755 /var/folders/nq/wkj89k854tl0w97n68qdn820pzk_51/T/gem.84634 /Users/matthew.evans/.rvm/rubies/ruby-2.0.0-p0/bin/gem
rm /var/folders/nq/wkj89k854tl0w97n68qdn820pzk_51/T/gem.84634
ERROR: While executing gem ... (NoMethodError)
undefined method `fu_stream_blksize' for #<Gem::Commands::SetupCommand:0x007ffd0e054818>
Installing RubyGems
Installing gem executable
I had the exact same error installing ruby v2 within rvm today. I was in a user account on Ubuntu who needed to use 'sudo' -- and enter my account password for sudo -- in order to install OS dependencies.
Your question mentions running rvm requirements to install dependencies. That seems to be new behavior in rvm, as of v1.19. It seemed to install a bunch of dependencies just fine. But then installing ruby bombed.
In earlier rvm versions, typing rvm requirements would just list the dependencies for rvm and for ruby, as in Archonic's answer.
I typed rvm implode and then started over with:
\curl -L https://get.rvm.io | bash -s 1.18.21
source /home/deploy/.rvm/scripts/rvm
rvm requirements
At that point I could install the libraries/tools that rvm said I needed for rvm and ruby, and then rvm install ruby-2.0.0-p0 succeeded.
I believe the issue is where RVM places your dependencies - global vs your user folder. From a book called "Agile development with rails":
First, you’ll need to make sure you have Xcode 3 or later installed...
$ xcodebuild -version
If you have Xcode version 3 installed, you’ll need to install the Git version control system separately. Verify your installation by running the following command:
$ git --version
Next, install RVM itself:
$ curl -L https://get.rvm.io | bash -s stable
Exit your command window or Terminal application and open a new one. This causes your .bash_login to be reloaded. Execute the following command, which provides additional installation instructions tailored to your specific operating system:
$ rvm requirements
Look for the line that tells you how to install the necessary OS dependencies for Ruby (MRI). Once you complete those instructions, you can proceed to install the Ruby interpreter itself:
$ rvm install 2.0.0
The preceding step will take a while as it downloads, configures, and compiles the necessary executables. Once it completes, use that environment, and install rails:
$ rvm use 2.0.0
$ gem install rails --version 4.0.0.beta1 --no-ri --no-rdoc
With the exception of the rvm use statement, each of the above instructions need only be done once. The rvm use statement needs to be repeated each time you open a shell window. The use keyword is optional, so you can abbreviate this to rvm 2.0.0. You can also choose to make it the default Ruby interpreter for new terminal sessions with the following command:
$ rvm --default 2.0.0
You can verify successful installation using the following command:
$ rails -v
If you have trouble, try the suggestions listed under the Troubleshooting Your Install heading on the rvm site.
Hope that does it for you!
This worked for me:
rvm get head
rvm requirements
rvm install ruby-2.0

Unable to run rake or rails commands (like rails c) - libcrypto error

When attempting to run any rake, rails or bundle commands, I get following error:
/home/username/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': libcrypto.so.1.0.0: cannot open shared object file: No such file or directory - /home/username/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/x86_64-linux/digest/sha1.so
I have tried rvm pkg install openssl, rvm remove 1.9.3, rvm reinstall 1.9.3, reinstall bundler and all gems. I read on another forum that I may have to uninstall rvm, ruby and rails and start from scratch. Ugh - really?
Thanks in advance.
you need to read and follow the instructions displayed with:
rvm requirements
then remove the rvm installed openssl:
rm -rf $rvm_path/usr/
and reinstall ruby:
rvm reinstall 1.9.3-p194

Removing all installed Gems and starting over

I recently started learning Ruby and Ruby on Rails, and have watched a plethora of getting started materials. I have been finding lately that I keep getting errors where gems won't install or they will be installed but they can't be used for some reason, and I have decided that I want to remove everything down to once again just having Ruby installed and start over with the installation. One training video had me install most of my gems with RVM, so I don't know if that changes anything.
So in short my question is "How to I get rid of RVM, Rubygems, and all installed Gems so that I can start over with just Ruby?"
Edit: I am on Mac OS 10.6
gem uninstall -aIx
Uninstalls all gems without prompt.
Options
-a, --[no-]all Uninstall all matching versions
-I, --[no-]ignore-dependencies Ignore dependency requirements while
uninstalling
-x, --[no-]executables Uninstall applicable executables without
confirmation
From the RVM support site:
RVM installs everything into ~/.rvm.
To remove RVM from your system run 'rm
-rf ~/.rvm'. You may have one additional config file in ~/.rvmrc and
of course the RVM hook in your
bash/zsh startup files.
So, just go to the command line and type rm -rf ~/.rvm
All the installed gems are in the ~/.rvm folders, so doing the above will remove the gems and installed rubies in one go.
Gems you added pre-RVM with the default ruby install can be removed by typing this at the command prompt:
for x in `gem list --no-versions`; do gem uninstall $x -a -x -I; done
For Windows and Unix copy/paste in command prompt (Ruby 1.9.x).
ruby -e "`gem list`.split(/$/).each { |line| puts `gem uninstall -Iax #{line.split(' ')[0]}` unless line.strip.empty? }"
using RVM, you could just type...
rvm gemset empty GEMSET
where GEMSET is the gemset which you would like to empty. then...
install bundle
yum install bundler and finally
bundle install
rvm implode (see cli docs) seems to work - and it even tells you where to look at for leftovers
This is work for me on Ubuntu 16.04. For me, when I was executing
command rails -v it throw errors because of NameError. I have
installed 3 version of rails (4.2.0, 4.2.6, 5.0.0.1). I was trying
to uninstall unnecessary gem using command gem uninstall rails -v
version number but I won't able to, but I find a way to solve
this problem. In order to uninstall all gems, you have to loop
through all entries in gem list with bash scripting. This method is
very inconvenient. Thanks to Rubygems 2.1.0, you now could do it
with one command.
STEP - 1
Firstly, please make sure you upgrade your Rubygems to 2.1.0 or
newer. For this run this command (Incase you are working on an older
version. You can check your gem version using this command any one
of them gem -v or gem --version)
gem update --system
gem --version
STEP - 2
Run this command in you terminal
gem uninstall --all
Step - 3
Install gem bundles (it is not necessary I think just for
precautions)
gem install bundle
Step - 4
Install the rails on your system using this command
gem install rails -v specific version you want to install you can check the rails version on the official site rails all versions
example :- I have installed rails 4.2.6
version, you install as per requirement.
gem install rails -v 4.2.6
Step - 5
Finally check the version of installed rails framework application
by Using basic command rails -v. It will echoed the current
version of rails frameworks. Enjoy :)
References
http://ruby-journal.com/how-to-uninstall-all-ruby-gems/
http://guides.rubyonrails.org/v4.1/getting_started.html
Step 1:
I first kept running into an error that said:
You don't have write permissions for the /usr/bin directory
To get permission, I became a root user with (this is potentially dangerous for reasons beyond my current understanding):
sudo -s
Credit
Step 2:
Then, I kept running into an error that said:
[gem] cannot be uninstalled because it is a default gem
This allowed me to uninstall everything:
for i in `gem list --no-versions`; do gem uninstall -aIx $i; done
Credit
FWIW, there are some weird cases where gems are installed but not really installed:
This should do the trick reasonably reliably.
gem uninstall -Iax `gem list | grep default | awk '{print $1}'`

Resources