I have installed 2 ruby versions on my using rbenv mac - 2.3.7 and 2.4.5
If i run command ruby -v following is the output:
ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-darwin18]
But if i run bundle install from my project, i get following error message:
Your Ruby version is 2.3.7, but your Gemfile specified 2.4.5
I have used rbenv to install different ruby version.
Try to add a .ruby-version file on your project's root:
$ echo 'ruby-2.4.5' > .ruby-version
$ cd .
That will set your Ruby version properly.
You're probably running a version of Bundler that was install using a different Ruby version. You can try reinstalling Bundler in your project folder:
gem install bundler
Related
I am trying to install Ruby on rails on a Mac Mojave:
$ brew install ruby
Warning: ruby 2.7.1 is already installed and up-to-date
To reinstall 2.7.1, run `brew reinstall ruby`
This shows me that I am running Ruby 2.7.1.
But when I check the version I get:
$ ruby --version
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
This tells me I am using Ruby 2.3.7.
I don't understand.
To run Rails I need >= 2.4.4 apparently:
$ sudo gem install rails
.....................
ERROR: Error installing rails:
zeitwerk requires Ruby version >= 2.4.4.
and
$ which ruby
/usr/local/opt/ruby/bin/ruby
So until I get ruby version to at least 2.4.4 I can't run rails.
Update
Install RVM on MAC as follows
$ brew install gpg
$ curl -L https://get.rvm.io | bash -s stable --autolibs=enabled --ruby
$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
Got these instructions from:
https://null-byte.wonderhowto.com/how-to/mac-for-hackers-install-rvm-maintain-ruby-environments-macos-0174401/
But then I install Rails:
$ sudo gem install rails
Successfully installed rails-6.0.2.2
Parsing documentation for rails-6.0.2.2
Done installing documentation for rails after 0 seconds
1 gem installed
and so I tried to crate a Rails project:
$ rails new blah
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
What is going on there? I seem to have successfully installed Rails but cannot create a Rails project.
The output from this command brew install ruby is not telling you that you're running ruby 2.7.1. That just says you already have ruby 2.7.1 installed for brew. But you could have other ruby versions installed in other ways. When you do
ruby -v
ruby executable is looked for in paths listed inside your environment variable PATH, in order. You can see those paths with
echo $PATH
So, managing different versions of ruby is hard and version managers exist for this reason. I suggest you to install rvm
When I try to start my Rails server, I get the following error:
$ bundle exec rails s
Your Ruby version is 2.3.7, but your Gemfile specified ~> 2.3.8
I don't understand why that happens though, since I set Ruby to 2.3.8 both using Homebrew and using rbenv. 2.3.7 is the version of the system's ruby. I am using Mac OS 10.14.4.
$ ruby -v
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-darwin18]
$ rbenv version
2.3.8 (set by /Users/ceasar/foo/.ruby-version)
$ which -a ruby
/Users/ceasar/.rbenv/shims/ruby
/usr/local/opt/ruby#2.3/bin/ruby
/usr/local/bin/ruby
/usr/bin/ruby
$ which -a bundle
/Users/ceasar/.rbenv/shims/bundle
/usr/local/bin/bundle
$ /usr/bin/xcodebuild -version
Xcode 10.2
Build version 10E125
$ brew list ruby#2.3
/usr/local/Cellar/ruby#2.3/2.3.8_1/bin/erb
/usr/local/Cellar/ruby#2.3/2.3.8_1/bin/gem
/usr/local/Cellar/ruby#2.3/2.3.8_1/bin/irb
/usr/local/Cellar/ruby#2.3/2.3.8_1/bin/rake
/usr/local/Cellar/ruby#2.3/2.3.8_1/bin/rdoc
/usr/local/Cellar/ruby#2.3/2.3.8_1/bin/ri
/usr/local/Cellar/ruby#2.3/2.3.8_1/bin/ruby
/usr/local/Cellar/ruby#2.3/2.3.8_1/include/ruby-2.3.0/ (25 files)
/usr/local/Cellar/ruby#2.3/2.3.8_1/lib/libruby.2.3.0.dylib
/usr/local/Cellar/ruby#2.3/2.3.8_1/lib/pkgconfig/ruby-2.3.pc
/usr/local/Cellar/ruby#2.3/2.3.8_1/lib/ruby/ (1211 files)
/usr/local/Cellar/ruby#2.3/2.3.8_1/lib/ (3 other files)
/usr/local/Cellar/ruby#2.3/2.3.8_1/share/emacs/ (7 files)
/usr/local/Cellar/ruby#2.3/2.3.8_1/share/man/ (4 files)
/usr/local/Cellar/ruby#2.3/2.3.8_1/share/ri/ (13487 files
$ bundle env | head -n 40
## Environment
```
Bundler 2.0.1
Platforms ruby, x86_64-darwin-18
Ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-darwin18]
Full Path /Users/ceasar/.rbenv/versions/2.3.8/bin/ruby
Config Dir /Users/ceasar/.rbenv/versions/2.3.8/etc
RubyGems 2.5.2.3
Gem Home /Users/ceasar/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0
Gem Path /Users/ceasar/.gem/ruby/2.3.0:/Users/ceasar/.rbenv/versions/2.3.8/lib/ruby/gems/2.3.0
User Path /Users/ceasar/.gem/ruby/2.3.0
Bin Dir /Users/ceasar/.rbenv/versions/2.3.8/bin
Tools
Git 2.19.2
RVM not installed
rbenv rbenv 1.1.2
chruby not installed
```
## Bundler Build Metadata
```
Built At 2019-01-04
Git SHA d7ad2192f
Released Version true
```
## Bundler settings
```
build.libv8
Set for the current user (/Users/ceasar/.bundle/config): "--with-system-v8"
build.mysql2
Set for the current user (/Users/ceasar/.bundle/config): "--with-mysql-config=/usr/local/Cellar/mysql#5.7/5.7.24/bin/mysql_config"
path
Set for your local app (/Users/ceasar/Desktop/beacon/.bundle/config): "vendor/bundle"
disable_shared_gems
Set for your local app (/Users/ceasar/Desktop/beacon/.bundle/config): true
```
I don't see anything here which would make me think it shouuld be using 2.3.7.
I'm not sure what else to try.
How does Bundler decide which version of Ruby to use, and how can I configure it to use either rbenv or my homebrew Ruby installation?
How about to try to use 'rvm'?
rvm install 2.4.2
This command will install another version of ruby, 2.4.2
And you can simply check the versions which all you have as
rvm list.
After this, run the version which you wish as the below,
rvm <version> or rvm use <version>
Hope this will help you!
Summary: The wrong version of bundler causes the problem. Use a ruby version manager to install the needed ruby version. Then install the correct version of the bundler gem for your project.
Details: In my case I'm running a rails example on github that required an older version of ruby and bundler and got the error described.
To manage my different ruby versions, I'm using ruby-install and chruby both installed with homebrew.
I followed these steps to resolve the problem on macOS Catalina v10.15.7:
Resolution steps
% ruby-install 2.4.1
# open a new shell so chruby will find 2.4.1
% chruby 2.4.1
% which ruby
/Users/richardlogwood/.rubies/ruby-2.4.1/bin/ruby
% gem install bundler:1.16.1
% which bundle
/Users/richardlogwood/.gem/ruby/2.4.1/bin/bundle
% cd (to the rails project directory)
# Note: it's a rails project so there was a binstub
# for bundler, hence `bin/bundler` in the project directory*
% bin/bundler install
% rake db:{create,migrate}
% bin/rails s
Before running the above steps, the error messages told me which version of ruby and bundler I needed to install. The system bundler was the wrong version (I'm on a mac) and the initial error message using that version gave me the error below. Only after installing the needed bundler gem (see above) was the correct ruby version resolved (see above).
Errors before resolution
% bundle install
Your Ruby version is 2.6.3, but your Gemfile specified 2.4.1
% which ruby
/Users/richardlogwood/.rubies/ruby-2.4.1/bin/ruby
% which bundle
/usr/bin/bundle
Note, the required bundler version was indicated by this error message:
Could not find 'bundler' (1.16.1) required by your ... /Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.16.1`
I don't suggest using RVM instead of RBEnv. RBEnv is one of the most up-to-date solutions around, and most people stick with it.
Can you please try running gem update --system to update your bundler first.
Install Rbenv and run the following commands in your project directory to install 2.3.8:
rbenv install 2.3.8
rbenv local 2.3.8
bundle install --path=vendor/cache
I had rbenv installed and also installed Ruby manually at some point because of certain issues which I thought I cleaned up. But it seems I had /usr/local/bin/{bundle,bundler} still present which was evident when I did: which bundle that showed it's location not under shims (belonging to rbenv) so I simply had to remove these e.g. rm -rf /usr/local/bin/{bundle,bundler} and all was working again.
I am trying to install Ruby & Rails on DigitalOcean droplet, I have downloaded ruby 2.5.1 with RVM but when I check version it says 2.31 and when I list available versions I get only 2.5.1.
I have tried rvm use 2.5.1 I got below problem
I fix it by running source ~/.rvm/scripts/rvm , then rvm use 2.5.1 and run bundle install, I get the following error,
can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
Below show the unstable issues faced from RVM and ruby versions
UPDATE
When I ssh into the server and run ruby -v, I get 2.5.1, then if I run
/bin/bash --login
I check ruby -v, its 2.5.1
install ruby 2.5.1 first, from your image it seems rvm already installed correctly
you just need to install it (it shows from your list command)
rvm install 2.5.1
# this to install version 2.5.1
rvm use 2.5.1
# active ruby 2.5.1
ruby -v
# check your version and make sure it said 2.5.1
to install bundler to your home directory use
# after you active ruby 2.5.1 then install bundler
gem install bundler
# my suggestion do not install with sudo
# in case you still has write problem below is other solution suggested [from here][1]
gem install bundler --user-install
This will install Bundler into your home directory. Note that you will need to append ~/.gem/ruby//bin to your $PATH variable to use bundle.
Whenever I run a Rails command, it states that my Ruby version is 2.3.1 but my Gemfile specified 2.5.1. However, "ruby -v" returns "ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]", my path has no references to ruby 2.3.1, and running "rvm list" shows a properly green highlighted 2.5.1. Bundler is installed, and when I try to run bundle install inside a created Rails folder, a get another "Your Ruby version is 2.3.1 but your Gemfile specified 2.5.1" message. Please advise.
$PATH:
-bash: /home/alowverus/.rvm/gems/ruby-2.5.1/bin:/home/alowverus/.rvm/gems/ruby-2.5.1#global/bin:/usr/share/rvm/rubies/ruby-2.5.1/bin:/usr/share/rvm/bin:/home/alowverus/.rvm/gems/ruby-2.5.1/bin:/home/alowverus/.rvm/gems/ruby-2.5.1#global/bin:/home/alowverus/.rvm/gems/ruby-2.5.1/bin:/home/alowverus/.rvm/gems/ruby-2.5.1#global/bin:/home/alowverus/.rvm/gems/ruby-2.5.1/bin:/home/alowverus/.rvm/gems/ruby-2.5.1#global/bin:/home/alowverus/.rvm/gems/ruby-2.5.1/bin:/home/alowverus/.rvm/gems/ruby-2.5.1#global/bin:/home/alowverus/bin:/home/alowverus/.local/bin:/home/alowverus/.rvm/gems/ruby-2.5.1/bin:/home/alowverus/.rvm/gems/ruby-2.5.1#global/bin:/home/alowverus/bin:/home/alowverus/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin: No such file or directory
Further information in response to answers:
"which rails" returns "/home/alowverus/.rvm/gems/ruby-2.5.1/bin/rails", as expected
Create two files in the root one .ruby-version mention ruby-2.3.1 and .ruby-gemset mention #gemset-name and cd back to the same directory which will create the rvm wrapper for that application then run
rvm current
which outputs like something
ruby-2.3.1#gemset-name
then run
gem install bundler
bundle
may be helpful for you
I would try (in no particular order):
which rails, is it the correct one?
bundle exec rails c (or whatever your command is)
rvm reload
To start clean, rvm implode and try reinstalling rvm and your Ruby version.
Your Ruby version is 2.3.8, but your Gemfile specified 2.3.1
check ruby version with ruby -v [version like 2.3.8] make sure ruby version should be same on ruby versions as well as in your GemFile if you have not the same version then your put command on your bash_profile (terminal) rbenv global 2.3.8 & rbenv shell 2.3.8 (the version you can specified accordingly ) then delete your Gemfile.lock then install bundle and install bundler . these steps working form me.
rbenv global 2.3.8
rbenv shell 2.3.8
delete your Gemfile.lock
install bundle
install bundler
I'm trying to bundle install a ruby project in Git Bash but I'm getting the above message.
ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [i836-mingw32]
gem -v
2.3.0
New to Ruby so its really frustrating. I'm trying to do the project below
http://www.viralrails.com/?p=25
This happens because you are specifying a Ruby version in your Gemfile (2.3.0) and this version is not installed or is not the current or default version.
Don't remove the line ruby '2.3.0' as someone said above. You app may have dependencies to this version. Do the following:
1) Check if you have Ruby 2.3.0 installed. If you are using rvm this may be done by
rvm list
and if you are using rbenv by
rbenv versions
2) If you don't have this Ruby version in your list of installed versions, then install it by issuing the following command
rvm install 2.3.0
and if you are using rbenv by
rbenv install 2.3.0
3) If you already had Ruby 2.3.0 installed or completed step 2 above, enter your app directory and issue the following command
rvm use 2.3.0
and if you are using rbenv by
rbenv local 2.3.0
Then run
bundle install
and I believe things will be ok.
Hope it helps!
Install bundler after installing ruby 2.4.0.
gem install bundler
If you installed bundler before installing ruby 2.4.0 then you should reinstall bundler or update it.
Also if the above command didn't work.
gem update bundler