OS X gem execution environment - ruby

NOTE: user377519 (answer below) pointed me in the right direction. I've posted the 'fix' at the bottom of the questions, in case you found this and need more than a 'pointer'
I can't figure out why the second call to "gem env" doesn't have the same environment as the first?
Any pointers? This is driving me crazy!!!!
$ which gem
/usr/local/bin/gem
$ /usr/local/bin/gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.8 (2010-06-26 patchlevel 1) [i386-darwin9.8.0]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-9
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.8
- /Users/pauliprice/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://gems.github.com", "http://gems.github.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gems.github.com
- http://gems.github.com
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.6 (2009-06-08 patchlevel 369) [universal-darwin9.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-9
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/pauliprice/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://gems.github.com", "http://gems.github.com"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gems.github.com
- http://gems.github.com
SOLUTION:
Given that you don't (as I do not) want to switch between different versions, merely install a new version, on you OSX 10.5 box, this is how to get RubyGems installed correctly.
Assuming you built and installed your new Ruby like this:
./configure --prefix=/usr/local --enable-pthread
sudo make
sudo make install
edit your ~/.bash_profile and add this line
export PATH=/usr/local/bin:$PATH
Save and refresh your terminal. Then you should install RubyGems like this:
Download and setup latest rubygems
wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
tar -xzv http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo su
# export PREFIX=/usr/local
# export GEM_HOME=$PREFIX/lib/ruby/gems/1.8
# export RUBYLIB=$PREFIX/lib/ruby:$PREFIX/lib/site_ruby/1.8
# ruby setup.rb all —prefix=$PREFIX
exit
edit ~/.bash_profile and add the following lines
export PREFIX=/usr/local
export GEM_HOME=$PREFIX/lib/ruby/gems/1.8
export RUBYLIB=$PREFIX/lib/ruby:$PREFIX/lib/site_ruby/1.8
And you're all good.
Refresh Terminal,

Ruby and its tools are "smart." They are aware of execution context and will look for configurations based on where they are started. The first execution is out of a system directory, while the later is out of your home directory.
Given that you have two different versions and you're on Mac, it means you had to have either installed Ruby manually or through RVM. Given that the newer version is out system directory, I guess that you attempted to install a newer version of Ruby manually and am now confused why it's not working for you. You installed it into system space, but did not update Ruby's configuration in your home directory. Unfortunately, I have no answer how to get you out of this position. Hopefully, you have something that will let you undo your install.
The far safer way of installing different copies of Ruby is to use Ruby Version Manager (RVM). It does all the magic necessary to install multiple copies of Ruby without changing the system. From the command line you can invoke using a different interpreter for that session. Thus, system stays untouched but you can run JRuby, v1.9.2, etc.
Hope this gets you in a direction.

Related

Jenkins Slave Doesn't Use Same Ruby Version As On Local Terminal

I am using a OSX Jenkins slave to run some build commands for Xcode. When I run gem environment in my local terminal, this is what I get.
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.2.0 (2014-12-25 patchlevel 0) [x86_64-darwin15]
- INSTALLATION DIRECTORY: /Users/nvitas/.rvm/gems/ruby-2.2.0
- RUBY EXECUTABLE: /Users/nvitas/.rvm/rubies/ruby-2.2.0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/nvitas/.rvm/gems/ruby-2.2.0/bin
- SPEC CACHE DIRECTORY: /Users/nvitas/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/nvitas/.rvm/rubies/ruby-2.2.0/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /Users/nvitas/.rvm/gems/ruby-2.2.0
- /Users/nvitas/.rvm/gems/ruby-2.2.0#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/nvitas/.rvm/gems/ruby-2.2.0/bin
- /Users/nvitas/.rvm/gems/ruby-2.2.0#global/bin
- /Users/nvitas/.rvm/rubies/ruby-2.2.0/bin
- /Users/nvitas/.rvm/bin
- /usr/local/opt/ruby/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
This is what I expect. Now when I run the exact same command through Jenkins, I get this
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.14
- RUBY VERSION: 2.0.0 (2015-04-13 patchlevel 645) [universal.x86_64-darwin15]
- INSTALLATION DIRECTORY: /Users/nvitas/.rvm/gems/ruby-1.9.2-p320
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
- EXECUTABLE DIRECTORY: /Users/nvitas/.rvm/gems/ruby-1.9.2-p320/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-15
- GEM PATHS:
- /Users/nvitas/.rvm/gems/ruby-1.9.2-p320
- /Users/nvitas/.rvm/gems/ruby-1.9.2-p320#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
I'm running everything in the same directory, the same user, nothing is different, so why is the ruby version and directories wrong? The only config setting in my Jenkins Slave is the PATH variable which has the value
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/nvitas/.rvm/gems/ruby-2.2.0/bin:/Users/nvitas/.rvm/bin:/Users/nvitas/.rvm/gems/ruby-2.2.0
Other than that everything is what comes installed.
When jenkins executes your script it doesn't access your local ~/.bash_profile or ~/.zhrc which will setup or reference your ruby package manager setup.
Add whatever is in either your ~/.bash_profile or ~/.zhrc to the build script in Jenkins project config.
In my case I'm using chruby, the simplest one in my experience - so I add this below #!/bin/zsh -l in jenkins script. Your first line might say #!/bin/bash...
source /usr/local/opt/chruby/share/chruby/auto.sh
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
chruby ruby-2.7.2
If you're using rbenv you would likely be including this instead:
~/.rbenv/bin/rbenv init
If you are using RVM please use the below script
export PATH="$PATH:$HOME/.rvm/bin"
Now you can run all rvm commands

unable to install jekyll on OSX

I am following this guide to install jekyll on OSX 10.7.3 and came up with the problem
ERROR: could not find gem jekyll locally or in a repository
I have tried:
sudo gem update --system (and get Nothing to update)
this post: How can I install Jekyll on Ubuntu 10.04 Server? , and it's no use.
I am not familiar with ruby and gem but I think this is needed:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.6
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-11
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/enzo/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://rubygems.org", "http://gems.github.com"]
- REMOTE SOURCES:
- http://rubygems.org
- http://gems.github.com
I don't know anything specifically about Jekyll, but there might very well be issues when running it with the system Ruby (that is, the one that comes with Mac OS).
Before wasting too much time bothering with the system Ruby (which could arguably be better left untouched), try to get either rbenv or rvm working. They allow you to install as many different versions of Ruby as you want without messing with the system Ruby, with each installation having its own gems.
Since you're not familiar with Ruby, I'll add that using rbenv or rvm is how most Ruby kids get their job done. Yes, it is an additional step that gets in the way, but it really does facilitate a smoother experience.
I recommend removing gems.github.com from your gem sources unless you really need it. GitHub ceased building gems from git repositories back in 2010. If you cannot remove it, then I recommend installing jekyll with the following command:
gem install --source http://rubygems.org jekyll
My rubygems environment for reference, as I'm on OS X 10.7.5.
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.6
- RUBY VERSION: 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-11
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/matt/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
I installed Jekyll directly into a new clean install of OSX Mavericks, and then wrote a quick post so I'd remember how to do it after I next reinstall my system. I've had plenty of feedback that others have had success following my guide, and no reports of anyone having any issues:
http://internet-inspired.com/wrote/install-jekyll-in-osx-mavericks/

"No such file to load" – can't install Ruby gems after Lion migration

I just migrated to a new Mac with OS X Lion. For some reson I can't install new Ruby gems anymore. Or rather: I can install them, but not find them.
This is my gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.6
- RUBY VERSION: 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-11
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/Jens/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Running the gem crack in irb works fine:
>> require 'rubygems'
=> false
>> require 'crack'
=> true
But when I try to do the same in my text editor (Textwrangler) I run into this:
custom_require.rb:31: in `gem_original_require': no such file to load -- crack (LoadError)
Any suggestions?
Maybe a pointer in the right direction: I've had problems on Lion with different ruby versions being installed. Problem was that some programs calling ruby (in my case git for a pre-commit hook) had their $PATH variable different; as a result another version of ruby was found first (and that version didn't have the gems installed).
So to debug, try printing out the version of both rubys (rubies?), and the PATH variable (something like print RUBY_VERSION and print ENV["PATH"]; maybe also print ENV["GEM_HOME"]. See if that leads to anything.
FYI: for me the solution in the end was to upgrade from git 1.7.3 to 1.7.7; it wasn't clear to my why things didn't work in 1.7.3 (why the PATH was different), but who cares; it works again :))

Can't install gems with bundler

I can't install gems with bundler, it always fail with a Can't find <inser-gem-name-here> in any of the sources message although I do have rubygems defined as a source in my gemfile.
Also, I can normally install gems with gem install <gem-name>, I used to install the ones that fail manually and then run bundle install so that it sees them as already installed, but that doesn't wrok anymore.
I used to use rvm, got tired of this issue (and thought it caused it) so I switched to rbenv to no avail. I'm running 1.9.2-p290.
I'm running Mac OS Lion. Thanks!
gem env output:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.10
- RUBY VERSION: 1.9.2 (2011-07-09 patchlevel 290) [x86_64-darwin11.2.0]
- INSTALLATION DIRECTORY: /Users/X/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /Users/X/.rbenv/versions/1.9.2-p290/bin/ruby
- EXECUTABLE DIRECTORY: /Users/X/.rbenv/versions/1.9.2-p290/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-11
- GEM PATHS:
- /Users/X/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1
- /Users/X/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.github.com", "http://rubygems.org", "http://gemcutter.org"]
- REMOTE SOURCES:
- http://gems.github.com
- http://rubygems.org
- http://gemcutter.org
Also
$which gem
/Users/X/.rbenv/shims/gem
And
$ which ruby
/Users/X/.rbenv/shims/ruby
I had a similar problem, that I managed to resolve by exporting my http_proxy
export http_proxy=http://user:password#host:port
Hope this helps.

How to delete a gem path?

How can I delete the second path (/home/tom/.gem/ruby/1.8) of GEM PATHS: ?
Here's the output of $ gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.5
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i486-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /home/tom/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://gems.rubyforge.org/
I appreciate the help!
Override in your ~/.bashrc file?
#in ~/.bashrc
export GEM_PATH=/usr/lib/ruby/gems/1.8
Feels kind of hacky though.
You can’t! I also wanted to do it, and haven’t found a way. Then I looked for in RubyGems source (at github.com) and learned that it tries to get the path from etc/gemrc and ~/.gemrc. If it fails (and fails GEM_PATH environment variable too), it assumes ~/.gem to be the default path.
Therefore, Max William is right, and you have either to export GEM_PATH or to create a ~/.gemrc. And it’s not a hack, for sure! :-)
Hope to have cleared things a bit!

Resources