I recently install ruby 2.7.1 using rbenv. I have made sure that .ruby-version and Gemfile file both have 2.7.1 as ruby version.
Now i cannot run rails s locally, doing so returns the following output in console:
Warning: the running version of Bundler (2.1.2) is older than the version that created the lockfile (2.1.4). We suggest you to upgrade to the version that created the lockfile by running gem install bundler:2.1.4.
Your Ruby version is 2.7.0, but your Gemfile specified 2.7.1
I have been searching and trying different things for hours but cannot figure out the problem and would be thankful for help.
Following output may help figure out the problem:
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
Checking for rbenv' in PATH: /usr/bin/rbenv Checking for rbenv shims in PATH: OK Checking rbenv install' support: /home/imran/.rbenv/plugins/ruby-build/bin/rbenv-install (ruby-build 20200819)
Counting installed Ruby versions: 1 versions
Checking RubyGems settings: OK
Auditing installed plugins: OK
bundle env
Environment
Bundler 2.1.4
Platforms ruby, x86_64-linux
Ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9cec0d0ffcba012279cd652d28ad5bf3) [x86_64-linux]
Full Path /home/imran/.rbenv/versions/2.7.1/bin/ruby
Config Dir /home/imran/.rbenv/versions/2.7.1/etc
RubyGems 3.1.2
Gem Home /home/imran/.gem/ruby/2.7.0
Gem Path /home/imran/.gem/ruby/2.7.0:/home/imran/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
User Home /home/imran
User Path /home/imran/.gem/ruby/2.7.0
Bin Dir /home/imran/.gem/ruby/2.7.0/bin
Tools
Git 2.25.1
RVM not installed
rbenv rbenv 1.1.1
chruby not installed
Bundler Build Metadata
Built At 2020-01-05
Git SHA 32a4159325
Released Version true
gem env
RubyGems Environment:
RUBYGEMS VERSION: 3.1.2
RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-linux]
INSTALLATION DIRECTORY: /home/imran/.gem/ruby/2.7.0
USER INSTALLATION DIRECTORY: /home/imran/.gem/ruby/2.7.0
RUBY EXECUTABLE: /home/imran/.rbenv/versions/2.7.1/bin/ruby
GIT EXECUTABLE: /usr/bin/git
EXECUTABLE DIRECTORY: /home/imran/.gem/ruby/2.7.0/bin
SPEC CACHE DIRECTORY: /home/imran/.gem/specs
SYSTEM CONFIGURATION DIRECTORY: /home/imran/.rbenv/versions/2.7.1/etc
RUBYGEMS PLATFORMS:
ruby
x86_64-linux
GEM PATHS:
/home/imran/.gem/ruby/2.7.0
/home/imran/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
GEM CONFIGURATION:
:update_sources => true
:verbose => true
:backtrace => false
:bulk_threshold => 1000
REMOTE SOURCES:
https://rubygems.org/
SHELL PATH:
/home/imran/.rbenv/versions/2.7.1/bin
/usr/lib/rbenv/libexec
/home/imran/.rbenv/plugins/ruby-build/bin
/home/imran/.rbenv/bin
/home/imran/.rbenv/shims
/home/imran/.rbenv/plugins/ruby-build/bin
/home/imran/.rbenv/bin
/home/imran/.local/bin
/home/imran/bin
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games
/snap/bin
/usr/local/texlive/2018/bin/x86_64-linux
my ~/.profile contains following statements:
export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"
export GEM_HOME="$(ruby -e 'puts Gem.user_dir')"
export PATH="$HOME/.rbenv/bin:$PATH"
Did You try to just update bundler as output said:
gem install bundler:2.1.4
or
gem install bundler
bundle update
rbenv creates shims based on version of ruby you install. Each time you change ruby version via rbenv global X.Y.Z or rbenv local A.B.C, rbenv will intercept the ruby command and redirect it to the appropriate ruby installation version which will look at its associated gems.
Therefore, if you set your local version to 2.7.1, and the error message you receive is telling you that your bundle version is different, you probably have not installed the bundler gem in the 2.7.1 Ruby shim.
To fix this, you can change your ruby version and install the gem:
rbenv local 2.7.1
ruby -v
# 2.7.1
gem install bundler
Now, ensure that in your Gemfile.lock you are using the same bundler version of the bundler gem you installed. If it is not, it means that the Gemfile.lock file was generated and bundled with a previous version. You can force update the Gemfile.lock by deleting and rebuilding, however, if you are collaborating with other developers you may want to speak with them before you do (and commit to source control)
#Gemfile.lock
BUNDLED_WITH 2.1.5
Related
My ruby version is 2.3.0, my mysql version is 8.0.23, my mysql2 version is 0.5.3, my rails version is 5.0.7.2, and my Xcode version is 12.5.
I use macOS Big Sur(version 11.4) and the text editor "Atom".
I'm planning to release my Rails application with the URL of HEROKU(example. https://[My APP Name].herokuapp.com).
I ran the following command.
$ bundle exec rake secret
bash: /usr/local/bin/bundle: /System/Library/Frameworks/Ruby.framework/Versions/2.3/
usr/bin/ruby: bad interpreter: No such file or directory
I installed the ruby version "2.3.0" as below ,because bundle seems to call "2.3".
$ rbenv install 2.3.0
Downloading openssl-1.0.2u.tar.gz...
-> https://****
Installing openssl-1.0.2u...
Installed openssl-1.0.2u to /Users/****/.rbenv/versions/2.3.0
Downloading ruby-2.3.0.tar.bz2...
-> https://****
Installing ruby-2.3.0...
WARNING: ruby-2.3.0 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.
ruby-build: using readline from homebrew
Installed ruby-2.3.0 to /Users/****/.rbenv/versions/2.3.0
I verified that the ruby version "2.3.0" is installed and the current ruby version is "2.3.0".
$ rbenv local 2.3.0
$ rbenv rehash
$ rbenv versions
system
* 2.3.0
$ rbenv global 2.3.0
$ rbenv rehash
$ rbenv versions
system
* 2.3.0
But the ruby current version is "2.6.3" when used the below command.
$ ruby -v
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3
- RUBY VERSION: 2.6.3 (2019-04-16 patchlevel 62) [universal.x86_64-darwin20]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.6.0
- USER INSTALLATION DIRECTORY: /Users/****/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
- GIT EXECUTABLE: /usr/local/bin/git
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /Users/****/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-20
- GEM PATHS:
- /Library/Ruby/Gems/2.6.0
- /Users/****/.gem/ruby/2.6.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Users/****/.rbenv/shims
I ran the following command.
$ bundle exec rake secret
bash: /usr/local/bin/bundle: /System/Library/Frameworks/Ruby.framework/Versions/2.3/
usr/bin/ruby: bad interpreter: No such file or directory
Would you like to tell me how to get rid of /usr/local/bin/bundle?
Because my bundle exec should work if I can get rid of /usr/local/bin/bundle.
And should I reinstall the Xcode ,that is command line tools? The 1st answer of the below URL recommends to try running xcode-select --install to (re)install the Xcode command line tools.
Cannot install Jekyll after updating to Catalina - An error occurred while installing ffi (1.9.18)
Looks like your /usr/local/bin/bundle precedes the bundle executable from rbenv in your PATH.
Could it be that you installed ruby with some other tools than rbenv (additionally to rbenv installation)?
In my macOS setup i do not have a file /usr/local/bin/bundle
$ ls /usr/local/bin/bundle
ls: /usr/local/bin/bundle: No such file or directory
and the bundle executable is loaded from my rbenv installation:
$ which bundle
/Users/***/.rbenv/shims/bundle
I think, if you can get rid of /usr/local/bin/bundle your bundle exec could work.
(you could try this with renaming the /usr/local/bin/bundle temporary, if you do not know how this bundle file was installed on your system)
Please see below the print out from gem env. It appears as the INSTALLATION DIRECTORY, USER INSTALLATION DIRECTORY and GEM PATHS are screwed up. I attempted to install ruby version 2.3.0 for another project and switch over to that. I uninstalled ruby version 2.3.0 and switch back to ruby version 2.3.1. I noticed these RubyGems environment variables got screwed up some how :( Everywhere you see '2.3.0', I think it's wrong.
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.1
- RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin15]
- INSTALLATION DIRECTORY: /Users/matthewsmith/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- USER INSTALLATION DIRECTORY: /Users/matthewsmith/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/matthewsmith/.rbenv/versions/2.3.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/matthewsmith/.rbenv/versions/2.3.1/bin
- SPEC CACHE DIRECTORY: /Users/matthewsmith/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/matthewsmith/.rbenv/versions/2.3.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /Users/matthewsmith/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- /Users/matthewsmith/.gem/ruby/2.3.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/matthewsmith/.rbenv/versions/2.3.1/bin
- /Users/matthewsmith/.rbenv/libexec
- /Users/matthewsmith/.rbenv/plugins/ruby-build/bin
- /Users/matthewsmith/.nvm/versions/node/v4.5.0/bin
- /Users/matthewsmith/.rbenv/shims
- /Users/matthewsmith/.rbenv/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
if there are multiple versions installed, project dependent version must be set as default.
To handle multiple projects with different dependencies, gemset can be used. RVM support gemset. Alternatives are available for rbenv also.
Nothing is wrong. I can see that you are using rbenv, and that your global ruby version is 2.3.1
If you run in your terminal:
gem env home
It will return something like:
/Users/matthewsmith/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
Apparently this line of code above tells that you have global rbenv version 2.3.1, and within li/ruby/gems folder you also have installed ruby version 2.3.0
In this folder .rbenv/versions/ will be all ruby versions you will about to install, or they are already installed.
When I install different ruby version let's say 2.3.0 I would do like this:
rbenv install 2.3.0 # install ruby version 2.3.0 using rbenv
rbenv local 2.3.0 # set ruby 2.3.0 to local project. It writes that version to a .ruby-version in your current directory
ruby -v # check your version to confirm that is 2.3.0 for a local project
gem install bundler
bundle install
Other options for installing ruby version are: SHELL and GLOBAL
rbenv shell 2.3.0 # Will temporarily change your Ruby version on your current shell. This sets the RBENV_VERSION environment variable in your terminal session.
rbenv global 2.3.1 # This will also change your Ruby version, but only the one you are using whenever no other version is specified, e.g. via a .ruby-version file or RBENV_VERSION variable.
NOTE! You don't need sudo to install gems. Typically, the Ruby versions will be installed and writeable by your user. No extra privileges are required to install gems.
reference
I hope it helps
I'm trying to run
env RAILS_ENV=test bundle exec rake db:migrate
and get the following error
Your Ruby version is 2.1.7, but your Gemfile specified 2.2.3
ruby -v
gives me
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
I'm using rbenv, if that matters. rbenv versions gives the following:
system
* 2.2.3 (set by /Users/thatsme/Projects/demoproject/.ruby-version)
So I have no ruby 2.1.7 installed. Spring is not running and I've run rbenv rehash. Then bundler gem is installed.
I'm going nuts on this. Can somebody please tell me why the wrong ruby version is being used? Thanks!
Running the command below helped me somehow:
rbenv exec gem install bundler
Assumption: You are using RVM.
This means there's a ruby version installed outside of RVM.
Clear your rvm rubies by running
rvm uninstall <ruby version>
once you have uninstalled all rvm rubies do ruby -v, if this returns an output specifying a ruby version then thats the root of the problem. Uninstall it with
sudo apt-get remove ruby
Now install your rvm rubies with rvm install <ruby version> and set it as default rvm use <ruby version>
Now install bundler
gem install bundler
And do bundle install
TLDR;
Check really carefully the content of your .bash_profile or .bashrc file.
None of the answers actually solve my problem. So here's my solution.
This is the error that I got:
$ bundle install
Your Ruby version is 3.0.1, but your Gemfile specified 2.7.1
I checked my rbenv setup:
$ rbenv versions
system
2.4.1
2.5.0
2.7.0
* 2.7.1 (set by /Users/setoelka/awesome-project/.ruby-version)
3.0.1
I uninstall the wrong version to probably reveal a new error. I can just install it again later, I was thinking.
$ rbenv uninstall 3.0.1
It does reveal a new error:
$ bundle install
-bash: /Users/setoelka/.gem/ruby/3.0.0/bin/bundle: /Users/setoelka/.rbenv/versions/3.0.1/bin/ruby: bad interpreter: No such file or directory
Ok, that's strange. I can just remove the .gem directory there.
$ rm -rf ~/.gem/
Now another new error:
$ bundle install
-bash: /Users/setoelka/.gem/ruby/3.0.0/bin/bundle: No such file or directory
It seems like my PATH variable is messed up. So I do:
$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 3.2.27
- RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-darwin20]
- INSTALLATION DIRECTORY: /Users/setoelka/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
- USER INSTALLATION DIRECTORY: /Users/setoelka/.local/share/gem/ruby/2.7.0
- RUBY EXECUTABLE: /Users/setoelka/.rbenv/versions/2.7.1/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /Users/setoelka/.rbenv/versions/2.7.1/bin
- SPEC CACHE DIRECTORY: /Users/setoelka/.local/share/gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/setoelka/.rbenv/versions/2.7.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-20
- GEM PATHS:
- /Users/setoelka/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0
- /Users/setoelka/.local/share/gem/ruby/2.7.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/setoelka/.rbenv/versions/2.7.1/bin
- /usr/local/Cellar/rbenv/1.1.2/libexec
- /Users/setoelka/opt/anaconda3/bin
- /Users/setoelka/opt/anaconda3/condabin
- /Users/setoelka/.cargo/bin
- /Users/setoelka/.gem/ruby/3.0.0/bin
- /Users/setoelka/.nvm/versions/node/v16.5.0/bin
- /Users/setoelka/.rbenv/shims
- /Users/setoelka/.rbenv/shims
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Library/Apple/usr/bin
So, it's clear I missed something when checking out my .bash_profile file. That's the problem there:
- /Users/setoelka/.gem/ruby/3.0.0/bin
That line was somehow buried under a plethora of settings inside my .bash_profile.
I had the same problem
I needed to run
bundle
to reinstall all my gems. then
bundle exec rails c
I run
gem install rubygems-update
but I get the following error:
ERROR: While executing gem ... (Gem::RemoteSourceException)
HTTP Response 302 fetching http://gems.rubyforge.org/yaml
My environemnt is:
~$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.1.0 (1.1.0)
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [i486-linux]
...
When I run:
$ ruby setup.rb
I get:
ruby: No such file or directory -- setup.rb (LoadError)
Please help.
First you need to successfully Installed Ruby. execute below command on console
ruby -v
If you get version of ruby then go ahead and download rubygems and extract the folder.
Suppose you download rubygems-1.8.17.tgz and extracted in /home/amit/rubygems1.8.17
cd /home/amit/rubygems1.8.17
ruby setup.rb
after successfully installed, do gem -v it should display gem version
If your RubyGems version is 0.8.5 or later, you can upgrade to the latest version with:
sudo gem update --system
If your current version of RubyGems is older than version 0.8.5, or specifically RubyGems 1.2.0, or you see the message “Nothing to update” when you tried gem update —system, then use the following commands:
gem install rubygems-update
update_rubygems
if your system requires root access to install ruby libraries, use sudo
Try updating your rubygems:
gem install rubygems-update --source http://production.s3.rubygems.org/
update_rubygems
If that doesn't work, this post:
Can't update RubyGems may help.
Check do you have setup.rb file or not. If you do have one then try to go into that where your file is located and the execute
ruby setup.rb
I am having problems with conflicting versions of Ruby that I have installed. I had 1.8.6 and then installed 1.8.7 and it has caused problems. I get the following error when trying to run my ruby on rails app:
/usr/local/lib/ruby/1.8/i686-linux/rbconfig.rb:7: ruby lib version (1.8.6) doesn't match executable version (1.8.7) (RuntimeError)
I would like to remove 1.8.7 somehow and just use 1.8.6 but have no idea how to go about doing this.
Ran into this same issue and thought I'ld share my findings. There was a 1.8.7 ruby version installed by an rpm (centos 6.3), and I compiled 1.9.3 from sources and put it in a directory /opt/upnxt/ruby. I changed my environment to:
export PATH=/opt/upnxt/ruby/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
export LD_LIBRARY_PATH=/opt/upnxt/ruby/lib64
export RUBYPATH=/opt/upnxt/ruby/bin
export RUBY_HOME=/opt/upnxt/ruby
export RUBYLIB=/opt/upnxt/ruby/lib64/ruby/1.9.1:/opt/upnxt/ruby/lib64/ruby/1.9.1/x86_64-linux
export GEM_HOME=/opt/upnxt/ruby/lib64/ruby/1.9.1
export GEM_PATH=/opt/upnxt/ruby/lib64/ruby/1.9.1:/opt/upnxt/ruby/lib64/ruby/gems/1.9.1
and then when running:
$ ruby /opt/upnxt/ruby/bin/gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.23
- RUBY VERSION: 1.9.3 (2012-11-10 patchlevel 327) [x86_64-linux]
- INSTALLATION DIRECTORY: /opt/upnxt/ruby/lib64/ruby/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /opt/upnxt/ruby/lib64/ruby/1.9.1/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /opt/upnxt/ruby/lib64/ruby/1.9.1
- /opt/upnxt/ruby/lib64/ruby/gems/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
When running without the 'ruby' command in front, I would get:
$ /opt/upnxt/ruby/bin/gem environment
/opt/upnxt/ruby/lib64/ruby/1.9.1/x86_64-linux/rbconfig.rb:7: ruby lib version (1.9.3) doesn't match executable version (1.8.7) (RuntimeError)
from /opt/upnxt/ruby/lib64/ruby/1.9.1/rubygems.rb:31:in `require'
from /opt/upnxt/ruby/lib64/ruby/1.9.1/rubygems.rb:31
from /opt/upnxt/ruby/bin/gem:8:in `require'
from /opt/upnxt/ruby/bin/gem:8
because of the default #!/usr/bin/ruby as stated earlier. I guess that's why one should use "#!/bin/env ruby" as a shebang instead (or "#!/usr/bin/env ruby")
If someone can tell me how to change the "RUBY EXECUTABLE" from the "gem environment" output so I won't need to specify it on the commandline, I would be grateful
cheers,
Gerrit
Yes, setting the path:
export PATH=yourrubypath/bin:$PATH
should do it.
I recommend you install rvm, that way you can run different ruby versions and manage gem sets in a very easy way
The installation instructions are here. However it basically reduces to:
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Then you can install a newer ruby from source (it will compile it!):
$ rvm install 1.9.1 ; rvm 1.9.1
$ ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
$ which ruby
/home/you/.rvm/ruby-1.9.1-p243/bin/ruby
You can go back to the "system" one doing:
$ rvm system
Just change your $PATH to point to the version you want.
I install ruby from the tarball (and not from the distribuition package). This way I can have several different versions working at the same time, I have just to update the $PATH in the session that I want to use a different version.
Your easiest path and future proof too would be using rvm. Download the version of ruby you want with rvm and make it the default.
Installation: http://rvm.beginrescueend.com/rvm/install/
Making it default:
rvm 1.8.6 --default
The whole process would take not more than 15 minutes. Everything is clearly explained in this. Your environment will be set before you finish watching this podcast:
http://railscasts.com/episodes/200-rails-3-beta-and-rvm