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.
Related
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
I have two versions of Ruby installed.
How can I install my ruby gem so that it gets installed in the version specified.
Normally you need to specify which Ruby you're using first, then call the appropriate gem command once that's set.
RVM, rbenv and others all work in different ways. For example, with RVM:
rvm use 2.4.1
gem install xyz -v 1.2.3
For rbenv it's a bit different:
rbenv local 2.4.1
gem install xyz -v 1.2.3
Where that generates a .ruby-version file in your current directory.
Since the gem command itself is Ruby, the proper Ruby environment must be set, which is where the multi-Ruby version managers come in.
I'm using OS X 10.10.5 (Yosemite). I'm trying to clone the github repo for MacDown. The instructions in the README say that after cloning one should do
git submodule init
git submodule update
bundle install
bundle exec pod install
I'm not a ruby programmer, so I had to install Bundler. The first two steps ran fine, but when I tried to run bundle install I got the error
activesupport-5.0.0.1 requires ruby version >= 2.2.2, which is incompatible with the current version, ruby 2.0.0p481
So I tried brew install ruby and now I have
saul#miniMac ✓ ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin14]
However, bundle install gives me the same error message as before. It's clear that it's finding the ruby at /usr/bin/ruby instead of the one at /usr/local/bin/ruby. How do I correct this?
I thought that perhaps the problem was that I had installed bundler before upgrading ruby, neither sudo gem uninstall bundler nor sudo gem uninstall bundle has any effect, and I don't know what else to try.
Here is all the output, in case it's relevant:
saul#miniMac ✓ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Resolving dependencies...
activesupport-5.0.0.1 requires ruby version >= 2.2.2, which is incompatible with
the current version, ruby 2.0.0p481
EDIT:
Thanks for the suggestions. I tried gem install bundler again, but it didn't help. I got the same error message. Here's what I get from bundle env
saul#miniMac ✗ bundle env
Environment
Bundler 1.13.6
Rubygems 2.0.14
Ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
Git 2.5.4 (Apple Git-61)
Gemfile
source 'https://rubygems.org'
gem 'cocoapods', '0.39.0'
Gemfile.lock
<No /Users/saul/Projects/macdown/Gemfile.lock found>
EDIT 2:
saul#miniMac ✓ which -a bundle
/usr/local/bin/bundle
/usr/bin/bundle
It seems that your PATH may have an entry that points to your older version of Ruby and despite having a newer version (2.3.1) it gets to use the first ruby binary it finds in one of the entries it finds in your PATH, which happens to be the old version. You could try to add your latest Ruby path as the first entry of your PATH variable, but in case a sub-shell is run and the default PATH is loaded the path to your latest Ruby would be overwritten. That being said, I think the easiest would be to use rvm here to make sure your environment is all set up with the version you intend to use at any given time. RVM can manage multiple versions of ruby in the same system. Read more about RVM here.
Run all the following commands in the same terminal window:
Install rvm: curl -sSL https://get.rvm.io | bash -s stable
Add rvm binary to PATH: export PATH="$PATH:$HOME/.rvm/bin"
Install ruby version you need: rvm install 2.3.1
Configure the current shell to use a specific version of Ruby like so: rvm use 2.3.1
Run bundle install again
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
I have two scripts which require the same version of Ruby. However, each script also requires a DIFFERENT version of a gem (nokogiri). One of the scripts will run with both versions of nokogiri (1.6.2.1 and 1.6.1). However the other script will ONLY run with version 1.6.1; and if 1.6.2.1 is installed, the script will not execute normally.
I know how to install multiple versions of Ruby with rbenv. But is it possible to install multiple instances of the SAME version of Ruby (2.1.2)? If so, how?
Make a local copy of a ruby-installer definition file using a custom name.
$ cp ~/.rbenv/plugins/ruby-build/share/ruby-build/2.1.5 2.1.5-nokogiri161
Install this as a custom definition file, no edits required.
$ rbenv install ./2.1.5-nokogiri161
Now you have a ruby version with a custom name and you can install custom gems on it.
$ rbenv shell 2.1.5-nokogiri161
$ gem install nokogiri -v 1.6.1
This is also useful for installing ruby versions with custom build flags. For example, a debug build with no compiler optimizations.
$ cp ~/.rbenv/plugins/ruby-build/share/ruby-build/2.1.5 2.1.5-debug
$ RUBY_CONFIGURE_OPTS="optflags=-O0" rbenv install ./2.1.5-debug
$ rbenv shell 2.1.5-debug
1) Use rvm instead of rbenv, and using it feature called 'gemsets' you could use different versions of gems for one version of ruby
rvm 2.1.1
rvm gemset create first second
rvm 2.1.1#first
gem install nokogiri -v 1.6.1
rvm 2.1.1#second
gem install nokogiri -v 1.6.2
2) or you can use bundler
gem install bundler
/dir_1/Gemfile
source 'http://rubygems.org'
gem 'nokogiri', '1.6.1'
/dir_2/Gemfile
source 'http://rubygems.org'
gem 'nokogiri', '1.6.2'
I see two options:
You could have different Gemfiles and let bundler take care of setting the right gem-version. If the scripts are in different directories, it should be no problem.
You could use rbenv-gemset to have separate gem-environments
There are undoubtly more, but those two seem the easiest for your setup.
Multiple instances of the same ruby is possible (regardless of the tool installing them) by just compiling them manually, with a different --prefix configured.
download the source
extract it
./configure --prefix=~/.rbenv/version/2.1.2-tSquirrel
make
sudo make install
This is how the rbenv-docs propose to achieve this.
You could also rename the current "2.1.2"-directory and then use ruby-build to install 2.1.2 again.
"Versions" in rbenv are just directories in ~/.rbenv/versions, I would guess you cold just rename/copy installed version and when you "select" version with "rbenv shell" you just declare from which directory you want to use binaries.