Updating ruby version with Rbenv but gems apparently not updated - ruby

I have just updated Ruby from version 1.9.3-p448 to 1.9.3-p484 using rbenv on a Ubuntu Production server. The updating seems to be successful. Ruby version shows the latest version I just updated.
However when I look at the gems for this version 1.9.3-p484 under the directory:
.rbenv/versions/1.9.3-p484/lib/ruby/gems/1.9.1/gems.
I only find a few gems in that directory. And when I looked at the directory of the previous version, there is a whole bunch of gems in there. Did I miss a step somewhere in the ruby update process?
Now that I am using the new ruby version, do I need to reinstall all the gems for this version? If so, will running bundle install does the job?

In short, yes. Since rbenv maintains a separate directory for each ruby installation, you'll need to run bundle again to install the gems for that ruby.
When you install a gem running under ruby 1.9.3-p448 for example, that gem will be installed only for that ruby. When you switch to another version of ruby, that gem will not be available for use until you install it.

Yes, you need to run bundle install for the active ruby version. Please make sure that the active ruby version, and the gemset for the application are set properly. Just do the following (in Linux/MacOS):
$ cat .ruby-version
ruby-1.9.3-p484
$ cat .ruby-gemset
your_app_name
And before gem update, please re-neter into the your application/gem folder.
$ cd ..
$ cd your_app_name
I have an additional note. If your application is a gem, there is no reason to add the .ruby-version, and .ruby-gemset files into the git repository, just add them into .gitignore file. When your application is a rails app, adding the files along with the Gemfile.lock into git repo has make sense, because you fix ruby version, and gem set for web-application to one that are those, which uniquely will work. Also some cloud services like heroku requires Gemfile.lock to be added into a git repo.

Related

Using a particular Ruby version on a project

I am trying to use a specific version of ruby on a particular project. I looked into the RVM and rbenv packages, but had little success with any of them.
These are the steps I took:
create project directory and navigate to it;
run rbenv install 2.3.1; after navigating to ~/.rbenv/versions I can see a "2.3.1" in there;
running "rbenv local" also echos 2.3.1;
My Gemfile is as follows:
ruby '2.3.1'
source 'https://rubygems.org/' do
gem 'test-kitchen'
gem 'kitchen-terraform'
end
However, when I run bundle install i get the following error:
Your Ruby version is 2.5.1, but your Gemfile specified 2.3.1
Its my first time working with Ruby, so I am struggling a little. I appreciate all help, and can provide more details if required.
If you store the ruby version of your project in .ruby-version and the gemset (i.e. gem list workspace) in .ruby-gemset of your project (which I recommend doing if the specific version is important to you), rvm should pick this up when you cd into your project directory. Sometimes it doesn't however depending on your setup or installation, in which case you can choose them explicitly with:
rvm use `cat .ruby-version`
rvm gemset use `cat .ruby-gemset
which I add to any installation scripts for example. You may need to run gem install bundler before running bundle install the first time you use the new gemset.
Set your default rbenv version like this:
$ rbenv shell jruby-1.7.1
See in: https://github.com/rbenv/rbenv#rbenv-shell

Bundler with rbenv version pathfile issue

So I am using rbenv to set my ruby version (for the specific project I'm working on this is 2.1.1). The issue is that bundler is unable to detect this change. I even tried to set the version in my gemfile:
source "https://my-proxy-address"
ruby "2.1.1"
gem 'fileutils'
gem 'json'
gem 'chef-api'
However this then causes the exact error message as seen here at the end of the tutorial:
username#hostname:~/Desktop/working-bundler-env$ rbenv version
2.1.1 (set by /Users/username/.rbenv/version)
username#hostname:~/Desktop/working-bundler-env$ ruby -v
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin15.0]
username#hostname:~/Desktop/working-bundler-env$ bundle install
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1
The tutorial has the solution to the issue (edit a pathfile), however they dont say what file to change. What file do I change?
$ rbenv
rbenv 1.0.0
Usage: rbenv <command> [<args>]
Some useful rbenv commands are:
commands List all available rbenv commands
local Set or show the local application-specific Ruby version
global Set or show the global Ruby version
shell Set or show the shell-specific Ruby version
install Install a Ruby version using ruby-build
uninstall Uninstall a specific Ruby version
rehash Rehash rbenv shims (run this after installing executables)
version Show the current Ruby version and its origin
versions List all Ruby versions available to rbenv
which Display the full path to an executable
whence List all Ruby versions that contain the given executable
See `rbenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/rbenv/rbenv#readme
$ which bundle
/usr/local/bin/bundle
So I noticed that when I ran gem bundle install the version was 1.13.3. After running sudo find / -name bundle I found two file locations that included that version number.
/Users/myusername/.gems/gems/bundler-1.13.3/exe/bundle
/Users/myusername/.gems/gems/bundler-1.13.3/lib/bundler/man/bundle
After attempting to run /Users/myusername/.gems/gems/bundler-1.13.3/exe/bundle install it works perfectly. So I just made an alias in my ~/.bash_profile that overwrote the incorrect bundle command.
alias bundle=/Users/alexcohen/.gems/gems/bundler-1.13.3/exe/bundle
The only side effect of this gem (for better or worse) is that it creates .bundle and path directories in the directory where I run bundle install where the gems are downloaded into.
I still have to investigate why this is happening, but I think that the bundle command in my macs terminal was referencing some type of broken bundler gem or file somewhere in my system.

Why can't bundler find rake when it's obviously installed?

I'm trying to migrate a version of Redmine from backup to a new server; I'm migrating from Redmine 3.2.3 to 3.3.0. I installed the new version of Redmine (from Bitnami Stack) on my new server and everything loads properly. When I move my old database into the new version, I have to run
bundle exec rake db:migrate
to migrate my database. But... bundler can't find rake somehow even though gem list shows it clearly installed. Can I force bundler to use the version of rake that I have installed that it says I don't?
I should mention I've done no customization at all, haven't installed any gems, or changed ruby versions or done anything. This is out of the box Redmine.
I noticed after I made the question that I had two versions of rake installed. I removed both and reinstalled rake 11.1.2 and have the same problem.
You are probably using the wrong ruby binary. Note that, the installers for Bitnami Stacks are completely self-contained and run independently of the rest of the software or libraries installed on your system.
Also, taking a look at the screenshots you have shared, you were using ruby 1.9.3 when you have executed ruby -v and the Redmine Bitnami Stacks uses ruby 2.1.9. Probably this is the reason of the issue you are having.
If you want to use the ruby (and the other components) shipped with the Bitnami Stack you need to run the following command:
cd *INSTALLDIR*
./use_redmine
This command will open a new console session with the environment configured to use the stack.
There are two things:
ruby gems available via gem list
ruby gems availbale via bundler
When you are using bundle then bundler is looking for gem from Gemfile. You can have multiple gems installed in your system, but when you are using Gemfile then gem version will be taken from Gemfile.lock
Summing up:
$ bundle exec rake ...
require to have rake gem inside Gemfile
$ rake ...
it will take the newest version of rake gem installed in system
I hope it helps you.
This is how I finally got my Redmine upgraded:
A version of ruby outside of the one provided by Bitnami somehow got installed on this machine as well as another version of bundler. The first thing I did was uninstall the apt-get version of bundler. I had to manually remove /usr/bin/bundler and /usr/bin/bundle for $ which bundle to stop finding bundler even after the removal.
I saw that the Bitnami stack's ruby was version 2.1.x but found Ruby 1.9.3 was installed to /usr/bin/ruby1.9.3/ with $ which ruby. I took the commands from here and removed that version of Ruby.
Running $ ruby -v now gave me nothing as Ruby wasn't installed anymore (even though it was in the Bitnami stack). Bitnami's Ruby then had to be (re?)added to my path in ~/.profile. $ ruby -v now gives me the correct version.
$ gem list was no longer telling me that rake was installed. I tried running $ bundle install where Gemfile is but was complaining about mime-types being locked at a lower version and wouldn't do anything. I got around that with $ bundle update but then ran into the infamous nokogiri problem where it complains that everything required by nokogiri isn't installed.
Since I'd dealt with this before (many many times) I went over to the Nokogiri Website's install page and followed the instructions for troubleshooting on Ubuntu:
sudo apt-get install build-essential patch
sudo apt-get install ruby-dev zlib1g-dev liblzma-dev
and now $ bundle update worked on my Gemfile. Redmine upgraded and my users are about as happy as users can get.

local ruby version not registering in gemfile

The Ruby project that I'm trying to run specifies a requirement for Ruby version 2.1.2 in the Gemfile. Accordingly, I installed that version using rbenv and set it as the version for that repo using rbenv's local command. However, even after powering off my computer and restarting (not to mention running rbenv rehash), I still can't start the project, however rbenv confirms that I'm running 2.1.2 in that directory
bundle exec foreman start
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.2
travis-web > rbenv version
2.1.2 (set by /Users/me/sites/travis-web/.ruby-version)
Do you know how I can get the gemfile to read/acknowledge the local version (2.1.2)?
Switching versions might have dropped your bundler. The previous version had it, the new one doesn't. See here for another related case.
Within that repo:
gem install bundler
rbenv rehash
rbenv-bundler is a handy library that can do this for you upon each bundle install

Your Ruby version is 2.0.0, but your Gemfile specified 2.1.0

When I try to bundle install I get the following message:
Your Ruby version is 2.0.0, but your Gemfile specified 2.1.0
In my Gemfile I have the following:
ruby '2.1.0'
And when I run ruby -v in the console I get:
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]
What does Ruby 2.1.0p0 mean? What version should I have in my Gemfile and why does the error tell me I have Ruby version 2.0.0?
Run
gem install bundler
or
gem update bundler
which may fix your problem.
For all new installed versions of Ruby you should update or install a new bundler.
In the top-level directory of your project, create a file named .ruby-version containing (wait for it...)
2.1.0
That apparently is the cross-{rbenv,rvm} way of spec'ing the version now.
For me, none of the answers helped. I fixed it closing and opening again the terminal.
If you get this in a Rails project, and you recently upgraded your Ruby version you might have spring still running with the old version of Ruby.
./bin/spring stop
will fix this.
None of the other suggestions was working for me. On the server, I had to do:
rvm --default use [correct version number]
brew cleanup ruby worked for me as I use HomeBrew to install Ruby.
I recently updated Ruby through HomeBrew but HomeBrew did not remove the older version. brew cleanup ruby will delete the older version of Ruby.
the main reason for this problem is your machine and gemfile using a different ruby version
so there is multiple problems and solutions for this issue you can try the below solutions one by one
1- make sure your machine install and use the same version of your gemfile if your machine not using the same one try to install this version using rvm
$ rvm install ruby_version_you_want
make sure the version installed success by using this command
$ rvm list
and if the new version doesn't set as a default you can set it using this command
$ rvm --default use ruby_version_you_want
you can check the current ruby version
$ rvm current
$ ruby -v
2- if you have the same issue check your bundler
$ gem install bundler
or
$ gem update bundler
3- in some cases spring still using the old version so you need to stop it
$ ./bin/spring stop
4- another case you can type
$ gem pristine --all
and try to install bundle again
5- also in some cases after install the updated ruby version you just need to restart your terminal.
6- another solution but I didn't recommend it the top-level directory of your project, create a file named .ruby-version containing your active running ruby version
7- if you still have this problem try to remove ruby and install the updated version only
$ aptitude purge ruby
If you are using Capistrano you should also check your deploy.rb file for the set :rbenv_ruby configuration.
I got this after upgrading with ruby-install. Fixed this with:
gem install bundler
followed by:
$HOME/.rubies/ruby-2.4.1/bin/bundle
It shouldn't be necessary to specify the path as which bundle indicates it's already using this path. But it gives the version error if running bundle without the path. I don't know why?
Thanks for the info about installing / updating bundler but it didn't work for me.
I had to do rbenv rehash
If you are using rbenv to manage your ruby environments you can run rbenv local 2.1.0 within your project directory to set the version of ruby your gemfile asks for.
NONE of the above answers worked for me, but
$ gem pristine --all
did the trick for me
buona fortuna
I struggled with something very similar, just different versions. I finally fixed it by going to RubyGems and placing the latest version of bundler in my gemfile, which currently is:
gem 'bundler', '~> 2.1', '>= 2.1.4'
There was still an issue, but after that, I ran:
gem update --system
And it resolved the mixed-up versions of Ruby in the rails project folder. You may have to restart the terminal before you do this. Also, I commented out the bundler gem file, it appears the gem update --system command is what really resolved it.
I got it from here:
For more advanced projects .versions.conf is supported, where more than the Ruby version can be specified.
Generating .versions.conf:
rvm --create --versions-conf use 1.9.3#my_app
Example .versions.conf:
ruby=jruby-1.6.8
ruby-gemset=my_app
env-JRUBY_OPTS=--1.9
Make sure your server configuration points to the correct ruby installation.
I had already updated my Ruby version in the .ruby-version file and that didn't fix it. ruby -v also showed the correct version, but I had forgotten to update my server config.
For example, with rbenv, NGINX, and Pushion Passenger I had in my NGINX server block:
passenger_ruby /Users/myusername/.rbenv/versions/2.3.1/bin/ruby;
And I needed to change to...
passenger_ruby /Users/myusername/.rbenv/versions/2.3.3/bin/ruby;
Then restarted NGINX and it worked.
This could happen when you install new version of ruby and update .ruby-version and Gemfile to the new version without doing install all the gems for new version of ruby first. So do the
$ bundle install
and you might as well need to source .profile or restart your shell.
If you are using rbenv just run
rbenv local 2.0.0
Then
bundle install
I opened Gemfile and replaced 2.7.1 with my own version of ruby 2.7.0 Everything is okay right now.
Had the same problem and I'm working with rbenv
Those are the steps that helped me fix my problem:
First in terminal, type which bundle. For me this gave: /usr/local/bin/bundle
Again in terminal try which ruby. In my case this gave: /Users/Mahmoud/.rbenv/shims/ruby
The problem here thus is that bundle isn't using the same ruby version from rbenv. So the path needs fixing. In other words I need to tell my terminal to use the rbenv version of bundle when I use bundle install.
So step 3: For me I personally already had the path set in ~/.bash_profile:
export PATH="$HOME/.rbenv/shims:$PATH"
eval "$(rbenv init -)"
but apparently this was not enough as I was using zsh. Had to add those same 2 lines to ~/.zshrc as well.
Restart terminal
Now bundle install is working as expected and which bundle gives:
/Users/Mahmoud/.rbenv/shims/bundle
indicating that the problem was just that bundle was using the wrong ruby.
So if you have this problem, just make sure ~/.bash_profile and ~/.zshrc have the correct path by adding the 2 lines indicated above. If this didnt work take a deep dive into paths to make sure that before starting which bundle gives the equivalent of:
/Users/Mahmoud/.rbenv/shims/bundle
Had the same error. Doing the following fixed it. I was using ruby 2.5.5 and rbenv. Upgraded from 2.5.1.
rbenv rehash
gem uninstall bundler
gem install bundler
gem install bundler:1.17.3 (my app needed specific bundler -v 1.17.3)
gem install rails
I solved this problem by updating my ruby version to ruby '2.4.0'
Then bundle install
Simply closing the terminal I was working on and opening a new one worked for me. Sometimes, updates are not effected immediately until a session is closed. I have found this as the case with many rails errors I faced.
I clean and install with that:
sudo gem pristine --all
and install again:
bundle install
I face the error msg
Your Ruby version is 2.5.1, but your Gemfile specified 2.3.0
and solved by the following steps:
open Gemfile which located at your directory.
change ruby '2.3.0' to ruby '2.5.1' and save the Gemfile
go back to items and run bundle update.
the issue is perfectly solved.

Resources