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

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

Related

How to install and run "hanami new bookshelf" from zsh

I installed the Hanami gem and ran hanami new bookshelf but got
zsh: command not found: hanami
I'm running:
macos 10.15.1
homebrew: 2.1.16
ruby: 2.6.5p114
rubygem: 3.0.6
hanami: 1.3.3
Does anyone know how to resolve this?
Same issue here; with a fresh installed MacOS Sierra, ruby & etc.
gem env output:
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.6
- RUBY VERSION: 2.6.5 (2019-10-01 patchlevel 114) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.6.0
- USER INSTALLATION DIRECTORY: /Users/captainhusaynpenguin/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /usr/local/opt/ruby/bin/ruby
- GIT EXECUTABLE: /usr/local/bin/git
- EXECUTABLE DIRECTORY: /usr/local/lib/ruby/gems/2.6.0/bin
- SPEC CACHE DIRECTORY: /Users/captainhusaynpenguin/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/2.6.5/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.6.0
- /Users/captainhusaynpenguin/.gem/ruby/2.6.0
- /usr/local/Cellar/ruby/2.6.5/lib/ruby/gems/2.6.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/opt/ruby/bin
- /usr/local/opt/ruby/bin
- /usr/local/opt/ruby/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
and finally, with the answer to a similar question by rubiii:
adding the EXECUTABLE DIRECTORY to PATH was the solution.
Quick command from above example:
export PATH=$PATH:/usr/local/lib/ruby/gems/2.6.0/bin
For permanently adding it to path:
sudo nano /etc/paths
was the fix.

Running a script from gem in GitHub in RVM

Can anyone help me walk through what I'm doing wrong here? This is my first go w/ Ruby so any help would be appreciated:
I've installed RVM and executing it through Terminal
I'm trying to run the script detailed in this post from GitHub:
https://github.com/michiels/helpscout-export
I was successfully able to install the gem 'HelpScout'
When I run ruby export.rb MY_api_key I get this error message:
ruby: No such file or directory -- export.rb (LoadError)
Anyone have any insight? Here's my current gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.0.0 (2013-11-22 patchlevel 353) [x86_64-darwin15.0.0]
- INSTALLATION DIRECTORY: /Users/stevekrause/.rvm/gems/ruby-2.0.0-p353
- RUBY EXECUTABLE: /Users/stevekrause/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
- EXECUTABLE DIRECTORY: /Users/stevekrause/.rvm/gems/ruby-2.0.0-p353/bin
- SPEC CACHE DIRECTORY: /Users/stevekrause/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/stevekrause/.rvm/rubies/ruby-2.0.0-p353/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /Users/stevekrause/.rvm/gems/ruby-2.0.0-p353
- /Users/stevekrause/.rvm/gems/ruby-2.0.0-p353#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/stevekrause/.rvm/gems/ruby-2.0.0-p353/bin
- /Users/stevekrause/.rvm/gems/ruby-2.0.0-p353#global/bin
- /Users/stevekrause/.rvm/rubies/ruby-2.0.0-p353/bin
- /Users/stevekrause/.rvm/bin
- /Library/Frameworks/Python.framework/Versions/3.5/bin
- /Users/stevekrause/anaconda/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin

/usr/bin/jekyll: No such file or directory

I am having troubles with jekyll. I have Ubuntu 14.04. I've tried to deploy a static site with rack-jekyll and I ended up messing up with my ruby and jekyll installation files.
I've already made ruby work just fine (I used rbenv to install version 2.2.3) but I still have problems with jekyll. When I type jekyll new smth or jekyll serve it shows:
bash: /usr/bin/jekyll: No such file or directory
I have already installed jekyll but it still shows that. From what I searched it might be a problem with some path.
Here are some information that might help to find a solution:
rafael#rafael-K56CM:~$ which jekyll
/home/rafael/.rbenv/shims/jekyll
rafael#rafael-K56CM:~$ sudo find / -name jekyll
[sudo] password for rafael:
/home/rafael/.rbenv/shims/jekyll
/home/rafael/.rbenv/versions/2.2.3/bin/jekyll
/home/rafael/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/jekyll-2.5.3/bin/jekyll
/home/rafael/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/jekyll-2.5.3/lib/jekyll
/home/rafael/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/jekyll-coffeescript-1.0.1/lib/jekyll
/home/rafael/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/jekyll-sass-converter-1.3.0/lib/jekyll
/home/rafael/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/jekyll-watch-1.2.1/lib/jekyll
rafael#rafael-K56CM:~$ gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.2.3 (2015-08-18 patchlevel 173) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/rafael/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0
- RUBY EXECUTABLE: /home/rafael/.rbenv/versions/2.2.3/bin/ruby
- EXECUTABLE DIRECTORY: /home/rafael/.rbenv/versions/2.2.3/bin
- SPEC CACHE DIRECTORY: /home/rafael/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /home/rafael/.rbenv/versions/2.2.3/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/rafael/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0
- /home/rafael/.gem/ruby/2.2.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["https://rubygems.org/", "http://rubygems.org/"]
- "gem" => "--no-ri --no-rdoc"
- REMOTE SOURCES:
- https://rubygems.org/
- http://rubygems.org/
- SHELL PATH:
- /home/rafael/.rbenv/versions/2.2.3/bin
- /usr/lib/rbenv/libexec
- /home/rafael/.rbenv/shims
- /home/rafael/.rbenv/bin
- /home/rafael/.rbenv/shims
- /home/rafael/.rbenv/bin
- /usr/local/heroku/bin
- /home/rafael/.rbenv/plugins/ruby-build/bin
- /home/rafael/.rbenv/shims
- /home/rafael/.rbenv/bin
- /usr/local/sbin
- /usr/local/bin
- /usr/sbin
- /usr/bin
- /sbin
- /bin
- /usr/games
- /usr/local/games
- /home/rafael/.rvm/bin
- /home/rafael/.rvm/bin
This issue can be solved by creating a symbolic link to the jekyll executable:
sudo ln -s /path/to/project/gems/bin/jekyll /usr/bin/jekyll
Use the which command to identify where the jekyll executable is installed.

bundle install hangs inexplicably

I am on RHEL 6, and have built Ruby from source and installed into /usr/local.
The server I am on does not have outside internet access, EXCEPT to access Rubygems.org. That is the only outside connection it is permitted to make. This is a corporate security restriction and there is nothing I can do, so please don't say 'use rvm'. I would if I could...
I need to run bundle install as a certain user, ciwasadm. But when I do, the terminal just hangs. When I run bundle install or gem install whatever as my username, wannia1, I am able to connect to Rubygems.org and get wahtever I need.
For some reason, the hanging only occurs when I am sudo'ed into ciwasadm. The Ruby installation for both users is working and I can run ruby files in the command line. I just don't understand why bundler is any different.
Running gem env for ciwasadm returns:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.0.0 (2015-04-13 patchlevel 645) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.0.0
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /home/ciwasadm/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.0.0
- /home/ciwasadm/.gem/ruby/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/bin
- /sbin
- /bin
- /usr/sbin
- /usr/bin
- /opt/groovy-1.8.3/bin
Running gem env for wannia returns:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.8
- RUBY VERSION: 2.0.0 (2015-04-13 patchlevel 645) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.0.0
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /home/wannia1/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.0.0
- /home/wannia1/.gem/ruby/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/bin
- /usr/lib64/qt-3.3/bin
- /usr/local/bin
- /bin
- /usr/bin
- /usr/local/sbin
- /usr/sbin
- /sbin
- /opt/groovy-1.8.3/bin
- /home/wannia1/bin
I'll post my solution here with the hopes that it helps someone else in the future.
Bundler was hanging because it could not reach the rubygems.org server. This is because a proxy was required, but had not been set.
I was able to run export http_proxy=<insert proxy info here> in my bash shell, and then was able to dial out.

OS X gem execution environment

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.

Resources