98

I am getting this error while running server, how do I fix this?

enter image description here

Emile Bergeron
  • 16,148
  • 4
  • 74
  • 121
unknown
  • 1,071
  • 1
  • 9
  • 14
  • I don't know if you have already fixed this issue but if not, please read this article . https://makandracards.com/makandra/21545-rbenv-how-to-switch-to-another-ruby-version-temporarily-per-project-or-globally – CHRIS LEE Dec 13 '17 at 14:36

13 Answers13

133

You better install Ruby 2.2.5 for compatibility. The Ruby version in your local machine is different from the one declared in Gemfile.

If you're using rvm:

rvm install 2.2.5
rvm use 2.2.5

else if you're using rbenv:

rbenv install 2.2.5
rbenv local 2.2.5

else if you can not change ruby version by rbenv, read here

Tan Nguyen
  • 2,770
  • 1
  • 17
  • 18
  • Backward compatibility is not an issue, I think. If it were the opposite (Gemfile specifying 2.3.0 and only 2.2.5 installed) we would have some issues, for sure. – Ed de Almeida Jun 20 '16 at 05:22
  • @EddeAlmeida what if I don't want to change the Gemfile? Like it's a project with multiple people? Or an open-source project – Emile Bergeron Dec 20 '16 at 02:50
  • Then install Ruby 2.2.5, create a private bundle for your app and go ahead, @EmileBergeron. – Ed de Almeida Dec 20 '16 at 02:55
  • 1
    These situations are exactly the reasons why I always suggest people to have a separate bundle to each application. – Ed de Almeida Dec 20 '16 at 02:58
  • 1
    I was having an issue between the local version of Ruby and the versions of Ruby that Heroku allows. I'm new-ish ro Ruby, Rails, and RVM, so this took me a bit to figure out. Thanks a TON, Tan. Specifically, no other answer I found in a couple hours of poking around mentioned the rvm use command. – Henry Edward Quinn IV Jan 20 '17 at 15:24
  • this caused my mac to ask me to re install rails even though it's already installed "Rails is not currently installed on this system" – Ayrad May 17 '17 at 01:36
  • rbenv install - doesn't work, install isn't a supported command. – mr-sk Jun 27 '17 at 16:26
  • I tried the above on rbenv and it didn't work for me. Turns out I was using rvm and not rbenv although both were installed. Make sure you upgrade the right ruby version manager' ruby version – Saurav Prakash Feb 21 '20 at 23:23
  • after having installed it, `rvm use 2.6.1` gives _Required ruby-2.7.0 is not installed._ :) how can I fix this ? – gordie Feb 27 '20 at 22:33
  • This may be off topic for some users but I had to do these commands as well. `rvm get stable --auto-dotfiles` then `bundler update --bundler` ... and then, I could use `rvm use 3.0.0` again, without errors/warnings – m_floer Mar 02 '21 at 07:05
  • In my case adding correct paths (`$HOME/.rbenv/shims` and `$HOME/.rbenv/bin`) to my .zshrc fixed the problem. Thanks @Tan – Dmitry May 28 '21 at 22:09
57

If you have already installed 2.2.5 and set as current ruby version, but still showing the same error even if the Ruby version 2.3.0 is not even installed, then just install the bundler.

gem install bundler

and then:

bundle install
Tarique
  • 3,369
  • 1
  • 29
  • 24
  • 6
    This is it right here! Because if you installed bundler before installing and setting your ruby version, calling `bundle check` or `bundle install` will still be referencing the ruby environment that was used for installing `bundler` originally. Cheers! – Joshua Pinter Oct 11 '18 at 05:09
  • 9
    Btw, I also had to do `rbenv rehash` after reinstalling bundler. – Joshua Pinter Oct 11 '18 at 05:10
  • 2
    Wow, I'd expect a missing gem error message then... anyway, thx! – Pengő Dzsó Jan 09 '20 at 19:07
  • @Tarique I still get the same error after running the suggested commands – java_geek Apr 07 '21 at 06:06
  • @java_geek It's better to install and switch the ruby version (2.2.5) using rvm or rbenv as already suggested by Tan. Also, make sure to change the desired ruby version in the ".ruby-version" file. Thanks. – Tarique Apr 25 '21 at 17:06
41

If you are using rbenv then make sure that you run the "rbenv rehash" command after you set local or global ruby version. It solved the issue for me.

rbenv rehash
kahcv
  • 556
  • 4
  • 7
24

Your Gemfile has a line reading

ruby '2.2.5'

Change it to

ruby '2.3.0'

Then run

bundle install
Ed de Almeida
  • 3,518
  • 4
  • 20
  • 52
5

A problem I had on my Mac using rbenv was that when I first set it up, it loaded a bunch of ruby executables in /usr/local/bin - these executables loaded the system ruby, rather than the current version.

If you run

which bundle

And it shows /usr/local/bin/bundle you may have this issue.

Search through /usr/local/bin and delete any files that start with #!/user/bin ruby

Then run

rbenv rehash

Mike
  • 79
  • 1
  • 1
3

Two steps worked for me:

gem install bundler

bundle install --redownload # Forces a redownload of all gems on the gemfile, assigning them to the new bundler
Kaka Ruto
  • 3,690
  • 1
  • 27
  • 33
3

it can also be in your capistrano config (Capfile):

set :rbenv_ruby, "2.7.1"
Dorian
  • 4,760
  • 1
  • 28
  • 43
2

Add the following to your Gemfile

ruby '2.3.0'
blnc
  • 4,276
  • 25
  • 41
2

I had this problem but I solved it by installing the version of the ruby that is specified in my gem file using the RVM

    rvm install (ruby version)

After the installation, I use the following command to use the the version that you installed.

    rvm --default use (ruby version)

You have to install bundler by using the following command in order to use the latest version

    gem install bundler 

After the above steps, you can now run following command to install the gems specified on the gemfile

    bundle install
2

Had same issue. I'm using rbenv and which ruby would show the rbenv version:

/Users/Mahmoud/.rbenv/shims/ruby

which bundle though would show:

/usr/local/bin/bundle

After looking in every possible place, turns out my problem was that I needed to update path in ~/.zshrc in addition to ~/.bash_profile (where I originally had the changes)

if you're running zsh add those two lines in ~/.zshrc (or the equivalent file) in addition to ~/.bash_profile

export PATH="$HOME/.rbenv/shims:$PATH"
eval "$(rbenv init -)"

After saving, quit terminal and relaunch before retrying. Hopefully this would help.

mrateb
  • 1,586
  • 2
  • 19
  • 46
1

I am on Mac OS Sierra. I had to update /etc/paths and add /Users/my.username/.rbenv/shims to the top of the list.

villy393
  • 2,899
  • 18
  • 26
0

For $ Your Ruby version is 2.3.0, but your Gemfile specified 2.4.1. Changed 2.4.1 in Gemfile to 2.3.0

0

If you have some dependency on the version of the Ruby , then install the appropriate version. otherwise change the version in the gemfile in the current directory.

rbenv install <required version>
rbenv local <required version>

Even after installation it was showing the same error for me, so I just restart the mac, then do the bundle install, it works :)

it should show something like this

   <user>@<repo>% rbenv versions 
      system
    * 2.3.7 (set by <app>)
arpit1714
  • 453
  • 5
  • 8