Ruby version - Error installing Rails - ruby-on-rails

I'm getting the next error installing RoR
How can I set the correct Ruby Version?
#####:path$ ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
#####:path$ sudo gem install rails
ERROR: Error installing rails:
activesupport requires Ruby version >= 1.9.3.
#####:path$

You shouldn't have to use sudo with gem install .... That's what's causing the mismatch between Ruby versions, since root is using the default installed Ruby, whereas your own account is using RVM's installed version.
Updating the system version of Ruby depends on your operating system, and usually lags behind the very latest version of Ruby. I've been using 2.0 for my latest project I launched last month. I doubt big OS vendors like Ubuntu or Apple are providing that version in their latest distribution. It's best that you manage your own Rubies whenever possible.
To install 1.9.3 you can run:
$ rvm install 1.9.3
then later
$ rvm use 1.9.3

You have :
###:path$ ruby -v
.....
###:path$ sudo gem install rails
...you said in your comment that :
$ sudo ruby -v
...gives you
ruby 1.8.7
To resolve this problem you shouldn't use sudo, as it tries to install using root session with 1.8.7 ruby version which is not supported.
To install rails just type the following without sudo:
$ gem install rails
...it should works as you've a supported ruby version (ruby 2.0.0p247)
You can check Install Ruby on Rails ยท Ubuntu Linux instructions (Which I found useful) if you've more troubles.

Related

Trying to install Rails 6 using RVM

I have installed RVM successfully on my Mac and using it I have installed Ruby 2.6.3. I have set my current and default version of Ruby to be 2.6.3. Everything seems to be fine because when I enter ruby -v into the terminal it tells me I'm using ruby 2.6.3.
My problem comes when I try to install Rails 6, I'm entering:
gem install rails --version=6.0.0 -no-ri -no-rdoc
It seems to install correctly however when I try to confirm with:
rails -v
I get:
Rails 6 requires Ruby 2.5.0 or newer.
You're running
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64- darwin18]
Please upgrade to Ruby 2.5.0 or newer to continue.
Why am I getting this message when my ruby -v command is telling me that I am using ruby 2.6.3
Any help would be very welcome.
You're running ruby 2.3.7p456. You need to set your local ruby version to 2.6.3.
Try which ruby to see which ruby version is loaded.
rvm install 2.6.3
rvm use 2.6.3
You can then see which ruby is running with which ruby.
See the basics on the rvm docs
As an aside, I also recommend recommend rbenv over rvm; however, you can only have one installed. If you have both installed, you're going to have a bad time.
To make sure you do not have both installed try which rbenv, and that should return rbenv not found
Please edit your original question with the output of the following commands:
which -a ruby
echo $PATH (That will help debug if your $PATH is set up incorrectly.)
which rbenv
ls (in your project directory)
i also had the similar problem which i resolved by uninstalling rvm completely and then installing rbenv.

Cannot install rails version 4.2.5 on Ubuntu in WSL when I have ruby 2.2.1 active. nokogiri requires Ruby version >= 2.3.0

Trying to install rails version 4.2.5 on Ubuntu in Windows Subsystem for Linux on Windows 10 when I have ruby 2.2.1 installed and active I get the following error:
~$ gem install rails -v 4.2.5
ERROR: Error installing rails:
nokogiri requires Ruby version >= 2.3.0.
I need these versions to collaborate on a project which uses these versions.
I started by installing WSL (1 not 2) on windows 10, then downloaded and installed Ubuntu Linux. Then I installed rbenv, updated dependencies, installed ruby 2.5.1 which was fairly easy.
I had problems installing ruby 2.2.1 but got there after doing
$ sudo apt-get install -y libssl1.0-dev
to install an earlier version of libssl which ruby 2.2.1 needs.
I installed node.js and an earlier version of bundler using
$ gem install bundler -v 1.17.3
as trying
$ gem install bundler
failed with a similar error.
(I also installed ruby 2.5.1 and rails 4.2.5 on top of it with few problems)
Trying various diagnostics showed rails was not installed for ruby 2.2.1
~$ rails
rbenv: rails: command not found
The `rails' command exists in these Ruby versions:
2.5.1
(but not in ruby 2.2.1, which is where I need it)
Looking at my files in windows File Explorer (only looking) I can see that while my ruby 2.5.1 gems include rails my ruby 2.2.1 files are incomplete and do not include rails.
I think the PATH is correct.
$ echo $PATH returns
/home/johnloughran/.rbenv/plugins/ruby- build/bin:/home/johnloughran/.rbenv/shims:/home/johnloughran/.rbenv/bin:/usr/
local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local
/games:/mnt/c/Program
Files/WindowsApps/CanonicalGroupLimited.Ubuntu18.04onWindows_1804.2019.522.0_
x64__79rhkp1fndgsc: ........ :/snap/bin
I modified my .bashrc file to add various entries to the PATH which have been included above.
I repeated the whole process twice starting from scratch (uninstalling Ubuntu) with the same block at the end.
What is my best option here to try and continue?
Thanks Josien for your comments. In the first case my collaborators have these versions of Ruby and Rails working together, but its a few years now since they installed them. One, David, helped me by trying a fresh install of rails 4.2.5 on ruby 2.2.1 which ran into the same problem above with nokogiri.
He solved it by installing a lower version of nokogiri in a new test directory, which I repeated as:
test$ gem install nokogiri -v 1.9.1
This worked. Then I installed rails as
test$ gem install rails --version 4.2.5
At last .... it worked!!!! :-)
To prove it I was able to get rails to return its version correctly.
test$ rails -v
Rails 4.2.5
Then I was able to create an app as
<working-directory>$ rails new learn-ruby
which works, almost, having hit another dependency problem, but hey ... that's programming!
Re your second comment I do not know enough about this stuff to know how relevant it is that this version of ruby is deprecated and the rails version is getting there too.

ERROR: Error installing rails on ubuntu

I'm getting the following error:
ERROR: Error installing rails:
mime-types-data requires Ruby version >= 2.0.
This happens while installing Rails on Ubuntu using the command:
sudo gem install rails
How can I fix this?
As the error suggests, you need Ruby version 2.0 or later.
You are probably using system ruby. Not sure about Ubuntu 16, but earlier versions used to come with Ruby v1.9.3. You can check your current Ruby version by running the following code in your terminal:
ruby -v
For easier rubies version management, I would highly suggest to use one of the popular ruby version managers:
RVM
rbenv
Install rvm and then install latest stable version.
# Using rvm
rvm install 2.3
# Using rbenv
rbenv install 2.3
The current ruby version in your system is below 2.0.
Try installing ruby 2.0 or higher versions before installing rails.
That will solve the problem.
I was facing the same problem trying to install rails with sudo.
I was getting: ERROR: Error installing mime-types-data: mime-types-data requires Ruby version >= 2.0
The thing is ruby -v gives me ruby 2.2.3p173 while sudo ruby -v gives me ruby 1.9.3p484.
So instead of sudo gem install rails I just did gem install rails and it worked.
Error: mime-types-data requires Ruby version >= 2.0
Notice: You shouldn't install rails with sudo permission.

Installing ruby using MacPorts

I'm installing Ruby using MacPorts.
After using the following command:
sudo port install rb-rubygem
I got the following error:
Error: Port rb-rubygem not found
What should I be doing?
This post is old but I'll add this here. If you want to use mac ports you can add ruby by using sudo port install ruby and then sudo port install rb-rubygems (notice you missed the 's' in rubygem*s* in your original post). You can always check what repositories are available in mac ports by typing port list. Hope this helps.
Ruby is installed by default in every mac. However, it's ruby 1.8, which is very old and shouldn't be used in any of your projects.
Take a look at rvm.
It will allow you to install several versions of ruby in the same system.
So, for example, you can do the following :
rvm use 1.9.3
ruby -v #=> ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin12.2.0]
rvm use 2.0.0
ruby -v #=> ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.1]
Using rvm, you can install any new version of ruby using the following :
rvm install 2.0.0-p0 #=> This will install Ruby 2.0.0
rvm install jruby #=> This will install jruby
And so on

Trying to install Rails 3, getting a strange "Ruby upgrade" notice

I'm trying to get my computer (Mac OS X, running Leopard) running with the latest version of Rails. Before this, I had 2.3.5. I tried following some instructions a few days ago, but didn't seem to make much progress. Now, I can't do anything in Rails. You'll see what I mean in a sec.
Theoretically, I've got the latest versions of Ruby:
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
$ sudo ruby -v
Password:
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9]
But if I try to run Rails, I get this error message:
$ rails testapp03
Rails requires Ruby version 1.8.7 or later.
You're running 1.8.6 (2008-08-11); please upgrade to continue.
And if I try to see which version of Rails I'm using, I get the same:
$ rails -v
Rails requires Ruby version 1.8.7 or later.
You're running 1.8.6 (2008-08-11); please upgrade to continue.
In case these are useful:
$ which ruby
/opt/local/bin/ruby
$ sudo which ruby
Password:
/opt/local/bin/ruby
$ which rails
/usr/bin/rails
So, the question: What have I done, and what do I need to do to get Ruby / RubyGems / Rails up and running on my computer?
What does which gem return?
Probably, your Ruby installation points to /opt/local/bin/ while the gem command is still referencing /usr/bin/.
When you installed the Gem, the Gem was saved in /usr/bin/ and loads the original system Ruby.
I don't know how you installed Ruby 1.8.7, however I would suggest you to take a step further: remove all your Ruby versions (except the system one, of course) and try RVM.
Try executing this command /opt/local/bin/ruby -v from the command line and see what version of ruby that come out.
Next find out where is the ruby gems is located with whereis ruby. I assume it should near /opt/local/lib/ruby-x.x/gems/.... Also try find out whether rails is installed under those directories. If not, your rails might be still pointing to the old ruby.
Also check if you have /usr/bin/ruby? If so, what is the output of /usr/bin/ruby -v ?
If it exists and rails is pointing to that version, So you should uninstall that ruby and rails, and install the rails gem all over again with /opt/local/bin/ruby

Resources