Ruby version and project not matching - ruby

When I run, bundle I see the following:
Your Ruby version is 2.5.0, but your Gemfile specified
2.4.0.pre.dev
my Gemfile looks like:
source 'https://rubygems.org'
ruby '2.4.0-dev'
gem 'sinatra', :github => 'sinatra/sinatra'
This is my gem env:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.12
- RUBY VERSION: 2.5.0 (2017-07-31 patchlevel -1) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /Users/johndoe/.rbenv/versions/2.4.0-dev/lib/ruby/gems/2.5.0
- USER INSTALLATION DIRECTORY: /Users/johndoe/.gem/ruby/2.5.0
- RUBY EXECUTABLE: /Users/johndoe/.rbenv/versions/2.4.0-dev/bin/ruby
- EXECUTABLE DIRECTORY: /Users/johndoe/.rbenv/versions/2.4.0-dev/bin
- SPEC CACHE DIRECTORY: /Users/johndoe/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/johndoe/.rbenv/versions/2.4.0-dev/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /Users/johndoe/.rbenv/versions/2.4.0-dev/lib/ruby/gems/2.5.0
- /Users/johndoe/.gem/ruby/2.5.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "-n/usr/local/bin"
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/johndoe/.rbenv/versions/2.4.0-dev/bin
- /Users/johndoe/.rbenv/libexec
- /Users/johndoe/.nvm/versions/node/v8.1.4/bin
- /usr/local/sbin
- /Library/Frameworks/Python.framework/Versions/3.4/bin
- /Users/johndoe/.rbenv/shims
- /Users/johndoe/google-cloud-sdk/bin
- /Users/johndoe/Library/Python/2.7/bin
- /Users/johndoe/.rbenv/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
When I type rbenv verions this is what I see:
system
2.0.0-p247
2.3.1
* 2.4.0-dev (set by /Users/johndoe/code/projects/blog-server/.ruby-version)
With Rbenv I am specifying the ruby version I want, and I am matching this in my project's Gemfile. However, whenever I run bundle or bundle exec gem uninstall sinatra I see the above error message about my ruby version and my gemfile ruby version not matching. I also see that my Ruby version is 2.5.0, and I have no idea how that got set. Can someone help me resolve this error?
Your Ruby version is 2.5.0, but your Gemfile specified
2.4.0.pre.dev
In my bash profile, I have:
export PATH=$HOME/.rbenv/bin:$PATH
....
eval "$(rbenv init -)"
In short, I just want the shell that runs my ruby process for my blog project to use ruby version 2.4.0-dev, and I am struggling to see understand what's blocking me and how to resolve it.
UPDATE:
I also noticed something odd. My bundler version continues to point to ruby 2.5.0p-1.
## Environment
Bundler 1.15.3
Rubygems 2.6.12
Ruby 2.5.0p-1 (2017-07-31 revision 59454) [x86_64-darwin16]
Git 2.11.0
Platform x86_64-darwin-16
OpenSSL OpenSSL 1.0.2k 26 Jan 2017
```
## Gemfile
### Gemfile
```ruby
source 'https://rubygems.org'
ruby '2.4.0-dev'
gem 'sinatra', '2.0.0'
```
### Gemfile.lock
```
<No /Users/johndoe/code/projects/blog-server/Gemfile.lock found>

In a project folder run:
rbenv local 2.4.0-dev
It should do the trick. You just need to specify local ruby version for this particular project. And your global version is set to 2.5.0

The best option here, I think, is to install Ruby Version Manager (rvm).
RVM helps every ruby developer by doing exactly what you need; manage ruby version automatically as you need.
Here's the link, hope it helps;
https://rvm.io/
Cheers

Related

Find where a specific Ruby version is installed

On Mac, I used to have rbenv as Ruby version manager but recently switched to asdf. I want to create a Ruby on Rails 7.0.4 but it uses an outdated version and I'd like to locate it.
$ rails new app
"Rails 7 requires Ruby 2.7.0 or newer.
You're running
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin"
$ which ruby
/Users/kawsay/.asdf/shims/ruby
$ ruby -v
ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c5) [arm64-darwin21]
$ irb
irb(main):001:0> RUBY_VERSION
=> "3.0.5"
$ asdf list ruby
2.7.4
*3.0.5
$ brew info ruby
==> ruby: stable 3.2.0 (bottled), HEAD [keg-only]
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.2.33
- RUBY VERSION: 3.0.5 (2022-11-24 patchlevel 211) [arm64-darwin21]
- INSTALLATION DIRECTORY: /Users/kawsay/.gem
- USER INSTALLATION DIRECTORY: /Users/kawsay/.gem/ruby/3.0.0
- RUBY EXECUTABLE: /Users/kawsay/.asdf/installs/ruby/3.0.5/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /Users/kawsay/.gem/bin
- SPEC CACHE DIRECTORY: /Users/kawsay/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/kawsay/.asdf/installs/ruby/3.0.5/etc
- RUBYGEMS PLATFORMS:
- ruby
- arm64-darwin-21
- GEM PATHS:
- /Users/kawsay/.gem
- /Users/kawsay/.gem/ruby/3.0.0
- /Users/kawsay/.asdf/installs/ruby/3.0.5/lib/ruby/gems/3.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/kawsay/.asdf/installs/ruby/3.0.5/bin
- /Users/kawsay/.asdf/shims
- /opt/homebrew/opt/asdf/libexec/bin
- /Users/kawsay/.cargo/bin
- /opt/homebrew/opt/openssl#2.8/bin
- /opt/homebrew/opt/python#3.8/bin/python3
- /opt/homebrew/bin
- /opt/homebrew/sbin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
$ which rbenv
rbenv not found
$ which rvm
rbenv not found
How can I find where ruby 2.6.8p205 is installed ?
You have an issue where you have system Ruby, brew Ruby, asdf Ruby, and rbenv Ruby. In short, your system is confused about where to find things.
The first step is to remove brew's Ruby installation:
brew uninstall ruby
The second step is to remove rbenv completely. (or use the official docs)
The third step is to make sure that system Ruby does not have the Rails gem installed. Start a shell without loading your profile so that you can bypass asdf and any other configuration:
env -i bash --norc --noprofile
Then confirm it's pointing at system Ruby: (your version will differ slightly depending on your version of macOS)
$ ruby -v
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin22]
Then uninstall the Rails gem:
gem uninstall rails
But while you're at it you might want to remove all the gems you installed using system Ruby: (ignore any errors here)
gem uninstall -aIx
Now close that shell session and switch back to your default shell. Make sure that your shell profile is cleared of anything related to rbenv and that you have no GEM_* environment variables being set. (assuming you use ZSH, check every ~/.zsh* file and ~/.gemrc) Then start a new shell session to load the cleaned profiles.
Then make sure asdf has a properly groomed environment:
asdf reshim
Now when you run gem env you should see output like this:
RubyGems Environment:
- RUBYGEMS VERSION: 3.4.1
- RUBY VERSION: 3.2.0 (2022-12-25 patchlevel 0) [arm64-darwin22]
- INSTALLATION DIRECTORY: /Users/foo/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0
- USER INSTALLATION DIRECTORY: /Users/foo/.gem/ruby/3.2.0
- RUBY EXECUTABLE: /Users/foo/.asdf/installs/ruby/3.2.0/bin/ruby
- GIT EXECUTABLE: /opt/homebrew/bin/git
- EXECUTABLE DIRECTORY: /Users/foo/.asdf/installs/ruby/3.2.0/bin
- SPEC CACHE DIRECTORY: /Users/foo/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/foo/.asdf/installs/ruby/3.2.0/etc
- RUBYGEMS PLATFORMS:
- ruby
- arm64-darwin-22
- GEM PATHS:
- /Users/foo/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0
- /Users/foo/.gem/ruby/3.2.0
Note the difference between INSTALLATION DIRECTORY and EXECUTABLE DIRECTORY in this output and yours. You need to have output that looks like this, otherwise that means that asdf is not installed properly and you should restart the installation of asdf from the beginning.
Afterwards, re-run gem install rails and you should be able to complete rails new app successfully.
If not, there is a shortcut to run commands with asdf for any given command:
asdf exec gem install rails
asdf exec rails new app
asdf exec rails server
This should bypass everything else and use asdf exclusively.

How to change gem environment for RUBY VERSION

I'm pretty new to Ruby and pod installation. Currently I have Ruby installed through RVM. However I'd like to install a pod through bundler by bundle exec pod install.
I keep getting the following error that my current version of Ruby is different from Gemfile specified. My current version of Ruby via RVM is same with Gemfile version. (So if I do pod install it won't cause any issues).
My gem env shows different Ruby Version.
How can I go about changing that? Where does gem env live? I saw some instructions here to install a RubyGem. But I'm having trouble following this. Any advice helps!
➜ ios git:(main) bundle exec pod install
Your Ruby version is 2.6.8, but your Gemfile specified 2.7.5
➜ ios git:(main) gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3.1
- RUBY VERSION: 2.6.8 (2021-07-07 patchlevel 205) [universal.x86_64-darwin21]
- INSTALLATION DIRECTORY: /Users/myusername/.gem
- USER INSTALLATION DIRECTORY: /Users/myusername/.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: /Users/myusername/.gem/bin
- SPEC CACHE DIRECTORY: /Users/myusername/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-21
- GEM PATHS:
- /Users/myusername/.gem
- /Users/myusername/.gem/ruby/2.6.0
- /Library/Ruby/Gems/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/

Weird issue with ruby version on mac

I am trying to create a rails app and fails like so:
$ rails new blog
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.
However, my ruby version is 2.6.3 according to my system:
$ ruby --version
ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
$ which ruby
/Users/flaab/.rbenv/shims/ruby
Rbenv has 2.6.5 activated.
$ rbenv versions
system
* 2.6.5 (set by /Users/flaab/.ruby-version)
mruby-dev
But it recognizes the wrong one as well.
$ which -a ruby
/Users/flaab/.rbenv/shims/ruby
/usr/bin/ruby
My gem env is...
flaab#MBP-de-Arturo ~ $ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3
- RUBY VERSION: 2.6.5 (2019-10-01 patchlevel 114) [x86_64-darwin18]
- INSTALLATION DIRECTORY: /Users/flaab/.gem
- USER INSTALLATION DIRECTORY: /Users/flaab/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /Users/flaab/.rbenv/versions/2.6.5/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /Users/flaab/.gem/bin
- SPEC CACHE DIRECTORY: /Users/flaab/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/flaab/.rbenv/versions/2.6.5/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-18
- GEM PATHS:
- /Users/flaab/.gem
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- "echo \"gem" => "--no-document\" > ~/.gemrc"
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/flaab/.rbenv/versions/2.6.5/bin
- /opt/local/libexec/rbenv
- /Users/flaab/.rbenv/shims
- /usr/local/bin
- /opt/local/bin
- /opt/local/sbin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /Users/flaab/bin
- /Users/flaab/.rbenv/shims
- /sw/bin
- /Users/flaab/.local/lib/npm/bin
- /Users/flaab/.composer/vendor/bin
How can I instruct gem to use the 2.6.5 version of ruby mentioned above?
Thanks in advance
To no avail. Ditched mac and went back to developing on debian. No issues.
Either run rbenv global 2.5.0 to set your global ruby or create a .ruby-version file in the app directory to instruct rbenv to use a specific version.
echo "2.5.0" >> .ruby-version and then try again.
Documentation
Do you have this already added to your .bash_profile ?
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
If not add the above lines to the bottom of the file, then close and restart your terminal(s).
It looks like your EXECUTABLE DIRECTORY may not be set correctly. Try the following command:
rbenv shell 2.6.5
Also, make sure you're in a new empty directory and do
rbenv local 2.6.5
Then try rails command again
rails new blog

bundle install using old rubygems version

I'm having what appears to be the exact same problem seen in a 1-month old question that no one has touched. I installed rbenv using homebrew, installed ruby 2.3.1 using rbenv install 2.3.1, installed jekyll and bundler using gem install jekyll and gem install bundler, then within a jekyll project, I typed bundle install. I got the error Rubygems 2.0.14.1 is not threadsafe, so your gems will be installed one at a time. Upgrade to Rubygems 2.1.0 or higher to enable parallel gem installation. When I run gem env, I see this:
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.6
- RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin15]
- INSTALLATION DIRECTORY: /Users/lindsb/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- USER INSTALLATION DIRECTORY: /Users/lindsb/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/lindsb/.rbenv/versions/2.3.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/lindsb/.rbenv/versions/2.3.1/bin
- SPEC CACHE DIRECTORY: /Users/lindsb/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/lindsb/.rbenv/versions/2.3.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /Users/lindsb/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- /Users/lindsb/.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/lindsb/.rbenv/versions/2.3.1/bin
- /usr/local/Cellar/rbenv/1.0.0/libexec
- /Users/lindsb/.local/bin
- /usr/local/sbin
- /usr/local/bin
- /Users/lindsb/.rbenv/shims
- /Users/lindsb/.local/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /opt/X11/bin
- /Library/TeX/texbin
I don't understand why bundler complains about Rubygems being below 2.1.0 when my Rubygems version is 2.6.6.
There is a Gemfile and a Gemfile.lock in the project directory. Gemfile looks like this:
source 'https://rubygems.org'
# jekyll
gem "jekyll", "3.1.1"
gem "redcarpet"
# compiling less
gem 'therubyracer'
gem 'less'
# minifying
gem 'jekyll-press'
# octokit
gem 'octokit'
gem 'netrc'
Hi I am learing Rails and encountered the same issue and I don't know what the root cause it is. But when I try reinstall bundler again
gem install bundler
and then run
bundle install
everything goes fine now.
I don't know exactly what the issue was, but when I removed Gemfile.lock and reran bundle install everything worked fine. There were probably just some bad constraints or something in Gemfile.lock.

Where is the "Gemfile" in Ruby?

I often see in documentation on the Internet, "put this in the Gemfile". I don't know where and what this "Gemfile" is. If I install a gem then I have installed it. Who need than a "Gemfile"? Where or what is the Gemfile, and why is it used?
The Gemfile is wherever you want it to be - usually in the main directory of your project and the name of the file is Gemfile.
It's convenient to have one because it allows you to use Bundler to manage which gems and which versions of each your project needs to run.
If you are not using Bundler (which you should!), then you can just install any gems you come across with gem install X and ignore instructions about adding a line to your Gemfile.
Read more about it here:
http://bundler.io/gemfile.html
http://bundler.io/man/gemfile.5.html
Gemfile is in Rails project, for Ruby run gem environment to find out about your gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.2.1 (2015-02-26 patchlevel 85) [i686-linux]
- INSTALLATION DIRECTORY: /home/gagan/.rvm/gems/ruby-2.2.1
- RUBY EXECUTABLE: /home/gagan/.rvm/rubies/ruby-2.2.1/bin/ruby
- EXECUTABLE DIRECTORY: /home/gagan/.rvm/gems/ruby-2.2.1/bin
- SPEC CACHE DIRECTORY: /home/gagan/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /home/gagan/.rvm/rubies/ruby-2.2.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/gagan/.rvm/gems/ruby-2.2.1
- /home/gagan/.rvm/gems/ruby-2.2.1#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /home/gagan/.rvm/gems/ruby-2.2.1/bin
- /home/gagan/.rvm/gems/ruby-2.2.1#global/bin
- /home/gagan/.rvm/rubies/ruby-2.2.1/bin
- /usr/local/heroku/bin
- /usr/lib/lightdm/lightdm
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /home/gagan/.rvm/bin
- /home/gagan/.rvm/bin
Notice the two sections for:
INSTALLATION DIRECTORY
GEM PATHS
Gemfile is a file which must be located in root of your rails project. It is used for describing gem dependencies for Ruby programs.
The first thing in your gemfile is a source in which you tell the Gemfile where to look for gems.
Source can be called as a block and you can have multiple sources in your gemfile.
source "https://my_awesome_source.com" do
gem "my_gem"
gem "my_other_gem"
end
Here is some documentation where you can read more about gemfile
http://bundler.io/gemfile.html
Just run gem update --system and you're good to go. It's that easy!!!

Resources