ruby: aliased to bundled_ruby - ruby

When I type in which ruby it always returns ruby: aliased to bundled_ruby
When I try which bundled_ruby it returns:
bundled_ruby () {
_run-with-bundler ruby $#
}
Then I try which _run-with-bundler and it returns:
_run-with-bundler () {
if _bundler-installed && _within-bundled-project
then
bundle exec $#
else
$#
fi
}
Where did all this come from and how do I get my which ruby to work again?
I am using OSX (v10.8.2), brew, rbenv, ruby-build, zsh

It can come from the bundler plugin of oh-my-zsh.
It uses magic to avoid typing bundle exec before the following commands: annotate berks cap capify cucumber foodcritic foreman guard jekyll kitchen knife middleman nanoc rackup rainbows rake rspec ruby shotgun spec spin spork strainer tailor taps thin thor unicorn unicorn_rails puma
You can disable this magic for some commands by defining the UNBUNDLED_COMMANDS environment variable in your ~/.zshrc before loading oh-my-zsh plugins (See oh-my-zsh pull request #2195).
export UNBUNDLED_COMMANDS=ruby
# for a list of commands
export UNBUNDLED_COMMANDS=(ruby irb rake)
Or you can simply remove the bundler plugin from you oh-my-zsh plugins.

This is part of rbenv "magic" to handle several ruby versions with several gem versions. Have a look at ~/.rbenv/shims/ruby, IIRC the script is defined there.
If you want to disable this, just unalias ruby: this deletes the generated alias.

Related

Using RVM via bash script

I wanted to write a small bash script to automatically setup the correct ruby version and gemset for a new project. For testing I have rvm installed with ruby 2.3.1 and two gemsets: foo and bar.
Even a simple test like this doesn't return what expected:
$ rvm current
ruby-2.3.1#foo
$ ./script
Using ruby-2.3.1 with gemset bar
Using /(...)/.rvm/gems/ruby-2.3.1 with gemset bar
ruby-2.3.1#bar
$ rvm current
ruby-2.3.1#foo
Contents of the script:
#!/bin/bash --login
rvm gemset use bar
rvm use 2.3.1#bar
rvm current
Other operations like installing rubies or creating gemsets seem to work, I just can't get use to modify the current version used by the script caller. Any ideas?
The answer was obviously simple, I should have called the script using
. ./script

Why bundle exec rake does not run to proper version of ruby

I am currently having a strange issue with bundler and ruby.
if I type:
$ which ruby
I get:
/home/martinos/.rubies/1.8.7-p370/bin/ruby
And when I type:
$ which bundle
I get
/home/martinos/.gem/ruby/1.8.7/bin/bundle
But for some reason when I run
$ bundle exec rake db:migrate
The task is run with ruby 1.9.3 (I have written a puts RUBY_VERSION in environment.rb)
Any one as an idea why this happens?
Here is more infos:
When I type:
$ which rake
I get:
/home/martinos/.gem/ruby/1.8.7/bin/rake
But if I
$ head -1 `which rake`
I get:
#!/usr/bin/env ruby1.9.1
There are a variety of pieces that could be in play. The first is that it could be a conflict between your Ruby version management tools and your global gems. Meaning, I suppose it is possible that you only have a Rake version that can work on Ruby 1.9.1 that is in your global set. So when you fire up Rake it is forced to run in Ruby 1.9.1.
What you may want to do is create a directory specific gemset. If you're using RVM you can see the documentation on how to do that by looking at their Gemset documentation. Once that is in place with the Ruby version you want to test with, then do a gem install of Rake at the version that will work with that Ruby version. At that point you should find that the Ruby version being used to run Rake in that directory will be the same as the version you have running.
I apologize if this does not answer your question, or if you have thought of this approach already. Trying to wrap my head around this without the ability to reproduce the problem is a tricky deal.

rake sometimes won't work until "rvm use"

I've got Ruby, Rails, Rake and friends all working pretty well using RVM on OSX, but when I start a new shell (new tab in Terminal.app) rake tasks seem to "lose" their environment:
$ rake my_module:my_task
Could not find uglifier-1.2.7 in any of the sources
Run `bundle install` to install missing gems.
If I issue "rvm use" (which, I believe merely prints the current ruby, but does not alter anything) then it works fine:
$ rvm use
Using /Users/username/.rvm/gems/ruby-1.9.3-p194
$ rake my_module:my_task # works fine now!
It seems to happen when a new shell is started. I have rvm installed as a single-user installation, with the following at the bottom of my .bash_profile:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
I've verified that my .bash_profile is in fact executing by putting some echo statements after that line; I see the echo on the command line when I open a new tab, so it seems to be working. Any idea why rake doesn't work without "rvm use"?
Try setting rvm ruby to default ruby
$ rvm use ruby-1.9.3-p194 --default
This should use the rvm ruby-1.9.3-p194 every time as default.

Why is Ruby bundler (w/ whiskey_disk and RVM) complaining that an installed Gem is not >=0?

This is my error message:
Running rake deploy:post_setup...
rake aborted!
You have requested:
nokogiri >= 0
The bundle currently has nokogiri locked at 1.5.5.
Try running `bundle update nokogiri`
Is this message telling me that 1.5.5 somehow does not meet the ">= 0" requirement? That doesn't sound right.
If I am interpreting this wrong, how should I interpret it?
(Ruby is jruby-1.6.7.2, bundle is 1.1.4. This rake task is actually run via whiskey_disk, if that's important.)
== EIGHT MONTHS LATER ==
I'm finding the same error. Again, trying to use whiskey_disk, so I suspect this is whiskey_disk-related.
This time, it's with the bcrypt gem.
3052 ~/dev/myproj$ bundle exec wd setup --to=grant
Deploying grant#<myserver>.com...
grant#<myserver>.com's password:
Repository already cloned to [/home/grant/myproj]. Skipping.
Running rake deploy:post_setup...
rake aborted!
You have requested:
bcrypt-ruby >= 0
The bundle currently has bcrypt-ruby locked at 3.0.1.
Try running `bundle update bcrypt-ruby`
Again, what the heck? I'm requesting something greater than 0, and it's complaining because the bundle has the gem and it's greater than 0! What's the problem?
The Gemfile contains simply gem 'bcrypt-ruby' - no version specified. Version 3.0.1 should be perfectly acceptable.
I've tried doing bundle update and bundle update bcrypt-ruby on the target server, but neither changes anything.
You are probably not using the correct ruby. Check which ruby is being used after you ssh into the machine. If you're using rvm, I would just uninstall the system ruby.
The problems came down to the fact that my RVM's Ruby wasn't being used by any of the remote commands. They kept using the distro's non-RVM Ruby.
So, two fixes were needed:
Needed to change the RVM path line in my .bashrc:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
need to be changed to prioritize RVM, like this:
PATH=$HOME/.rvm/bin:$PATH # Add RVM to PATH for scripting
I needed to load RVM in my post_setup.sh and post_deploy.sh scripts, so that the succeeding rake commands would use my RVM ruby.
This was accomplished by adding the following to each:
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
exit -1
fi
(The latter was clearly not written by me, given how polished it is. I lifted it from one of my firm's other projects, where they've clearly dealt with this before.)
I also need to run bundle install in my post_setup.sh and post_deploy.sh scripts. This must occur before whiskey_disk starts running Rake, so including it in the Rake script itself is not sufficient.
And now I have whiskey_disk deployments working smoothly.

Trying Ruby: why can't I install nanoc?

I try to install nanoc http://nanoc.stoneship.org/docs/2-installation/
by typing in irb
gem install nano
it says undefined variable or method 'nanoc' ?
You need to install it from the shell, not IRB. Gem is a command, i.e.
% which gem
/usr/bin/gem
% gem install nanoc
ian.
That gem install command is meant to be run in your normal system shell (something like Bash, for example).
irb is a Ruby shell, it interactively executes Ruby code. You'll notice that the instructions you link to immediately tell you to quit irb after starting it (they only told you to run it to make sure Ruby was installed).

Resources