ERROR: Error installing rails on ubuntu - ruby-on-rails

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.

Related

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.

How to install the Nokogiri gem using Ruby 1.9.3

I'm using Ruby 1.9.3 with my Rails v3.2.19 application and I'm unable to run bundle because Nokogiri requires a Ruby version >= 2.1.0. At the moment I cannot upgrade my Ruby version and I really need to install Nokogiri otherwise my app won't run.
Besides the regular solutions using gem install, I've already tried the following command line with no success:
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2
ERROR:
>Error installing nokogiri:
nokogiri requires Ruby version >= 2.1.0.
Is there a way that I can install Nokogiri using my current Ruby version?
Additional Info:
Rails version - 3.2.19
Ruby version - 1.9.3
Nokogiri version - 1.7.0.1
OS - CentOS 7
The last version of nokogiri to support Ruby 1.9.3 was 1.6.8.1, so you need to do something like
gem install nokogiri -v 1.6.8.1
First try update xcode command line tools xcode-select --install
Then try these steps https://github.com/sparklemotion/nokogiri/wiki/What-to-do-if-libxml2-is-being-a-jerk

An error occurred while installing autoprefixer-rails (6.2.2). Additionally it say's "autoprefixer-rails requires ruby version >= 2.0. "

Im facing this problem when i'm installing bunder using command "bunlde install"
Initially i tried solving this issue by using following command
gem install autoprefixer-rails -v '6.2.2'
but again it said "autoprefixer-rails requires ruby version >= 2.0."
when i type
"ruby -v", my ruby version shows 2.3.0.
Next i have tried adding
ruby '2.3.0' to my gem file, then there was a conflict saying your ruby version is 1.9.3 but your gem file has 2.3.0
Need help how to proceed further.
Change your ruby version in the system first. If you using rvm then use following command.
rvm use 2.3.0
If you don't have it then install it by following command
rvm install 2.3.0
Delete the Gemfile.lock file and run
bundle install
Hopefully it will work. Thank you

Ruby version - Error installing 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.

Error on install gem factory_girl and ruby version

I try to install skylinecms but I have a problem with installing the gem.
The gem factory_girl asked me to use version> = 1.9.2 of Ruby
atmoner#atmoner:~/base_ror$ sudo gem install skylinecms
ERROR: Error installing skylinecms:
factory_girl requires Ruby version >= 1.9.2.
ruby -v
atmoner#atmoner:~/base_ror$ ruby -v
ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-linux]
I have tried to change ruby version to 1.9.2
atmoner#atmoner:~/base_ror$ rvm use 1.9.2
Using /home/atmoner/.rvm/gems/ruby-1.9.2-p320
But still same problem
atmoner#atmoner:~/base_ror$ sudo gem install skylinecms
ERROR: Error installing skylinecms:
factory_girl requires Ruby version >= 1.9.2.
what's the source of this problem?
you have an idea?
You shouldn't use sudo with rvm, as it creates a new subshell with a completely new environment. See more about sudo and rvm here: RVM and 'sudo'
Most likely your system ruby version is 1.8.7, and that is what is getting invoked when you run sudo gem install skylinecms. You can verify that with the following commands:
rvm use system
ruby -v
Try installing the skylinecms gem without sudo.
Best to use per-project gemsets as suggested in rvm best practices

Resources