I have a shell script that is changing between different directories, setting up various projects. Each project has a .ruby-version file.
How can I get rbenv to change to the appropriate ruby version in each directory?
I have something like this right now:
Dir.chdir(target) do
run('rbenv install -s')
run('eval "$(rbenv init -)" ' \
'&& gem install bundler ' \
'&& rbenv rehash ' \
'&& bundle install')
end
But I'm getting this error:
Successfully installed bundler-1.12.0
1 gem installed
Your Ruby version is 2.2.2, but your Gemfile specified 2.1.5
Command `eval "$(rbenv init -)" && gem install bundler && rbenv rehash && bundle install` failed with status 18
Any ideas?
Related
I'm on Linux Mint 17.2.
I recently removed ruby with apt-get purge ruby.
I then installed rbenv and then did rbenv install 2.3.0 so now, ~/.rbenv/versions/2.3.0/bin/ruby exists.
But now, I can't do gem install rubocop. I get this:
$ gem install rubocop
rbenv: gem: command not found
The `gem' command exists in these Ruby versions:
2.3.0
But I can do ~/.rbenv/versions/2.3.0/bin/gem install rubocop.
However, once I'm done, I can't use it:
$ rubocop --auto-correct
-bash: /usr/local/bin/rubocop: /usr/bin/ruby1.9.1: bad interpreter: No such file or directory
I also can't find out where this ruby came from:
$ dpkg -S /usr/bin/ruby1.9.1
dpkg-query: no path found matching pattern /usr/bin/ruby1.9.1
It's possible it was installed via RVM a long time ago.
Any idea how I can fix my Ruby?
try run rbenv global 2.3.0 && rbenv rehash
It looks like you haven't run the rbenv shell magic to add bin shims to your path.
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
It's recommended to add that to your .bashrc or .bash_profile so it gets executed on login.
Take a read through this - it covers rbenv and bundler but the initial setup will be what you need to look at.
After installing rbenv, I wanted to switch to the correct Ruby version to work on a project, but there seems to be an issue recognizing it.
$ cd project/
$ bundle install
$ Your Ruby version is 2.0.0, but your Gemfile specified 2.1.1
$ rbenv local
$ rbenv: no local version configured for this directory
$ rbenv global
$ 2.1.1
$ ruby --version
$ ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
Am I overlooking something?
There was an issue with my $PATH variable.
This worked for me (in .bash_profile):
export PATH="/usr/local/bin:$PATH"
eval "$(rbenv init -)"
To install rbenv, I installed Cygwin and some required packages (gcc, openssl, libssl, libxml, etc). Then, cloned repositories and appended to.zshrc.
$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugin
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(rbenv init -)"' >> ~/.zshrc
Restarted cygwin and ran this command.
rbenv install 2.0.0-p353
However I got this error.
$ rbenv install 2.0.0-p353
Downloading ruby-2.0.0-p353.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/78282433fb697dd3613613ff55d734c1
Installing ruby-2.0.0-p353...
BUILD FAILED
Inspect or clean up the working tree at /tmp/ruby-build.20140211033802.7944
Results logged to /tmp/ruby-build.20140211033802.7944.log
Last 10 log lines:
installing default gems: /cygdrive/c/Users/MY_NAME/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0 (build_info, cache, doc, gems, specifications)
bigdecimal 1.2.0
io-console 0.4.2
json 1.7.7
minitest 4.3.2
psych 2.0.0
rake 0.9.6
rdoc 4.0.0
test-unit 2.0.0.0
/cygdrive/c/Users/MY_NAME/.rbenv/plugins/ruby-build/bin/ruby-build: line 759: /cygdrive/c/Users/MY_NAME/.rbenv/versions/2.0.0-p353/bin/ruby: No such file or directory
/tmp/ruby-build.20140211033802.7944 is here:
https://gist.github.com/anonymous/a9e099a4335ae59a9714
I found a function related to openssl around line 759 of ruby-build, but I may have installed
it.
Any ideas on why versions/2.0.0-p353/bin/ruby doesn't exist?
In attempting to use Bundler with ruby 1.9.3p194 managed with rbenv in the fish shell I receive the error:
> gem install bundler
Fetching: bundler-1.5.1.gem (100%)
> bundle install
fish: Unknown command 'bundle'
Rbenv is being initialized in config.fish like so:
set -x PATH "$HOME/.rbenv/bin" $PATH
. (rbenv init - | psub)
And the output of rbenv init -:
> rbenv init -
setenv RBENV_SHELL fish
. '/Users/nifl/.rbenv/libexec/../completions/rbenv.fish'
rbenv rehash 2>/dev/null
function rbenv
set command $argv[1]
set -e argv[1]
switch "$command"
case rehash shell
eval (rbenv "sh-$command" $argv)
case '*'
command rbenv "$command" $argv
end
end
I don't have fish set up as the default shell and Bundler is working fine in Bash.
Derp. Needed rehash after > gem install bundler
> rbenv rehash
Another issue that can appear is when using rbenv-communal-gems. jruby does not like the communization, it wants this:
rbenv sequester jruby-1.7.12
This allows you to re-run
gem install bundler
rbenv rehash
And then you can use the bundle command again.
In my Gemfile I specified ruby version 2.0.0:
ruby '2.0.0'
But my console tells me I have 2.1.0dev:
$ ruby -v
ruby 2.1.0dev (2013-09-16 trunk 42951) [x86_64-darwin12.4.0]
I am using rbenv and it tells my I don't have 2.1.0 installed,
$ rbenv versions
system
* 2.0.0-dev
Bundle update or bundle install says:
"Your Ruby version is 2.1.0, but your Gemfile specified 2.0.0"
but using 'rbenv local 2.0.0-dev' leaves me with ruby 2.1.0dev again. Furthermore:
$ rbenv global
2.0.0-dev
$ cat ~/.bash_profile:
export PATH="$HOME/.rbenv/bin:$PATH"
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi
As far as I know, 2.1.0dev doesn't even exist yet.
How can i get ruby 2.0.0 selected?
You may need to update your version of ruby-build to make sure you have the update where ruby-2.0.0-dev switched to follow the ruby_2_0_0 branch.
Try running ruby-build --version and make sure it's one of these (or later):
v20130907
v20130901
v20130806
v20130628
v20130518
v20130514
v20130501
v20130408
v20130227
v20130226
v20130225
If not, run brew upgrade ruby-build.
Go to your Gemfile and change the description there
I just got the same problem and couldn't find a "working" solution. So I made my own.
source 'https://rubygems.org'
ruby '2.0.0' #Change this one to this '2.1.0'
gem 'rails', '4.0.3'