A client has jenkins setup on a macOS machine. It's doing iOS builds and uses bundler to install some gems. One gem recently started requiring a dependency which in turn requires ruby >= 2.1
Installing jwt 2.1.0
Gem::InstallError: jwt requires Ruby version >= 2.1.
An error occurred while installing jwt (2.1.0), and Bundler cannot continue.
For one, I've installed rvm and ruby 2.1.0 on the macOS machine
osxbuildserver:~ jenkins$ ruby -v
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin14.0]
and for the ssh login user it shows up fine. The issue is that even tough Jenkins runs under the same jenkins user
root 15102 1 15102 0 0 Ss ?? 0:00.04 sshd: jenkins [priv]
jenkins 15106 15102 15102 0 0 S ?? 0:00.03 sshd: jenkins#ttys000
it still uses the system ruby which is 2.0.0. In one of the builds I've added a shell script with ruby -v
[EnvInject] - Variables injected successfully.
[workspace] $ /bin/sh -xe /var/folders/6v/xlw3p2pn47d2jl_jghf25dn00000gr/T/hudson73325394438439334.sh
+ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
Calling
ssh jenkins#osxbuild "echo $PATH"
from my local machine, returns the incorrect path
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
but login in with the same user is fine
osxbuildserver:~ jenkins$ echo $PATH
/Users/jenkins/.rvm/gems/ruby-2.1.0/bin:/Users/jenkins/.rvm/gems/ruby-2.1.0#global/bin:/Users/jenkins/.rvm/rubies/ruby-2.1.0/bin.... etc
I've already tried the answer from here Jenkins using System Ruby - use rvm ruby? but it didn't help.
my .bash_profile contents
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home
export ANDROID_HOME=/Users/jenkins/Library/Android/sdk
export ANDROID_SDK=$ANDROID_HOME
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$JAVA_HOME
export TESSDATA_PREFIX=$HOME/tesseract-ocr
source ~/.profile
source $HOME/.rvm/scripts/rvm
The question is quite old but probably somebody will use my solution.
I copied everything that gave me echo $PATH. Then I opened Jenkin's configuration and found "Global properties".
I added PATH and as a value I added value from terminal.
Related
I'm getting this error message when I try to do a pod install on Mac on a Turbo Module in React Native. I believe it's because of my version of Xcode installed.
> RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
Your Ruby version is 3.1.2, but your Gemfile specified 2.6.8
When I run ruby -v it returns 2.6.8.
> ruby -v
ruby 2.6.8p205 (2021-07-07 revision 67951) [universal.arm64e-darwin21]
I'm not sure what to do to fix this or where it's finding 3.1.2.
2.6.8 is the builtin ruby in macOS Monterey, which can be found at /usr/bin/ruby. If bundle is finding 3.1.2 then you have another version of ruby installed (possibly via homebrew?). You can see all versions of ruby on your current PATH using the command which -a. The order of results is the order in which they are found on the PATH, as you can confirm by typing echo $PATH. Execution is on a first-come-first-served basis. On my machine the which command produces:
% which -a ruby
/opt/homebrew/opt/ruby/bin/ruby
/usr/bin/ruby
showing that I have a homebrew copy of ruby first on my PATH, followed by the macOS copy.
Similarly, you can check which installation of bundle is being used:
% which -a bundle
/opt/homebrew/opt/ruby/bin/bundle
/opt/homebrew/lib/ruby/gems/3.1.0/bin/bundle
/usr/bin/bundle
You can override the PATH ordering by editing .zshrc (long-term change); by explicitly setting it to a new set of path values in the current terminal (one-time change for the active terminal window); or by typing the fully qualified path name of the version of the command you wish to run (ex: /usr/bin/bundle ... to use the system version).
I installed Ruby using rbenv. I am using Mac. For one of my project I am using ruby 2.6.3. For my other project I need ruby 2.7.4. So I installed both the versions.
In my first project, if I do rbenv versions, it correctly shows
system
* 2.6.3 (set by /Users/suganyas/academics/project1/.ruby-version)
2.7.4
For my second project, i set ruby version 2.7.4 using the command
rbenv local 2.7.4
So if I do rbenv versions from my second project, it again shows,
system
2.6.3
* 2.7.4 (set by /Users/suganyas/project2/ceep/.ruby-version)
But when I do bundle install, I am getting the following error
Your Ruby version is 2.6.3, but your Gemfile specified 2.7.4
Full trace is here
The git source `git://github.com/sqlninja/outdatedbrowser_rails.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
The git source `git://github.com/nhodges/phantomjs-gem.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
The git source `git://github.com/heapsource/active_model_otp.git` uses the `git` protocol, which transmits data without encryption. Disable this warning with `bundle config git.allow_insecure true`, or switch to the `https` protocol to keep your data secure.
Following files may not be writable, so sudo is needed:
/Library/Ruby/Gems/2.6.0
/Library/Ruby/Gems/2.6.0/build_info
/Library/Ruby/Gems/2.6.0/cache
/Library/Ruby/Gems/2.6.0/doc
/Library/Ruby/Gems/2.6.0/extensions
/Library/Ruby/Gems/2.6.0/gems
/Library/Ruby/Gems/2.6.0/specifications
Your Ruby version is 2.6.3, but your Gemfile specified 2.7.4
Kindly help me what am I doing wrong.
Running the below commands helped me in choosing the correct rbenv local versions
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
I'm not sure what Ruby version is being used on my device (macOS) by default.
ruby -v outputs ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
brew list ruby --versions outputs ruby 3.0.2
rbenv versions outputs
system
* 2.7.4 (set by /Users/nlakritz/.rbenv/version)
If ruby -v shows 2.6.3, then you are using the ruby which ships with the system by default. You can confirm this in several ways. Running the shell command which ruby will show /usr/bin/ruby. Checking your PATH will show /usr/bin earlier than the location of the homebrew or rbenv installations.
If you wish to run one of the others, you can put it earlier on the PATH or invoke it explicitly by giving the fully qualified name such as /usr/local/opt/ruby/bin/ruby myscript.rb. Another alternative which avoids twiddling the PATH variable is to use a shebang line at the beginning of different scripts pointing explicitly to the version to use with that script.
It depends what you mean by 'default'. If you're running a file with ruby filename then the version you are using is 2.6 (because you're running the same Ruby as ruby --version).
If you're running a file directly (eg. ./filename.rb) then it depends on the shebang line in the file. For example, the file could start with the line #!/usr/bin/ruby, so to check which version of ruby that file is running on, you could call /usr/bin/ruby --version.
Hopefully that helps, but I'm not 100% sure I understood what you're asking - so let me know :)
Try this:
$ which ruby
/usr/bin/ruby
$ irb
irb(main):001:0> RUBY_VERSION
=> "2.7.0"
So, rbenv is ignored, I think you're missing this in your path:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
ruby -v # should say 2.7 now
And if it says 2.7, you can add the export and eval commands at the bottom of your ~/.bashrc to load it every time you open a shell, thus kicking off rbenv override.
I would bet 2.6 for you, ie ruby -v.
I'm trying to debug a Rails project within RubyMine v2018.2 (2018.2.1, 2018.2.4). When I start the editor I get a warning:
RubyMine Gem Manager: RubyMine has detected that some of the gems required for 'project' are not installed.
When I try to run RubyMine's Bundler install command I'm told
bash -c "RBENV_VERSION=2.5.0 /usr/bin/rbenv exec bundle install -V"
Activating bundler (< 2) failed:
Could not find 'bundler' (< 2) among 28 total gem(s)
Checked in 'GEM_PATH=/home/brad/.gem/ruby/2.5.0:/var/lib/gems/2.5.0:/usr/lib/x86_64-linux-gnu/rubygems-integration/2.5.0:/usr/share/rubygems-integration/2.5.0:/usr/share/rubygems-integration/all', execute `gem env` for more information
To install the version of bundler this project requires, run `gem install bundler -v '< 2'`
...and when I try to run or debug my application from the IDE I'm told "Could not find bundler (version) required by your project-path/Gemfile.lock."
Why doesn't RubyMine detect my installed Gems?
My environment
Ubuntu 18.04.01
zsh 5.4.2
rbenv 1.0.0
rbenv-binstubs # 8ecb7ca8
Rubymine 2018.2.4
I'm using rbenv to manage my Ruby versions. The system has Ruby 2.5.1 installed, but my project depends on 2.5.0. I've set 2.5.0 as the rbenv global version. Configuration for how rbenv chooses a Ruby version seems okay; I get the following results from the noninteractive commands:
> echo $RBENV_VERSION
(no response)
> cat ~/.rbenv/version
2.5.0
> rbenv global
2.5.0
After noticing rbenv wasn't working properly in some RubyMine commands I moved the eval "$(rbenv init -)" setup step from by ~/.zshrc up to ~/.zshenv and ~/.profile so it will also apply to bash and zsh login shells (per guidance here). I'm now getting matching results for interactive and login shells, but still getting unexpected behavior from the Bundle install command within RubyMine.
What is working
My application installs, builds and runs just fine from an interactive shell.
RubyMine's Ruby SDK settings correctly detect rvm and its installed versions, and all of the installed gems for that version.
What I've tried
The output from the bundle install command claims it's running
bash -c "RBENV_VERSION=2.5.0 /usr/bin/rbenv exec bundle install"
When I run this from my interactive shell or with RubyMine's "Run anything" feature (login shell) this command works fine - as does any of the following:
RBENV_VERSION=2.5.0 /usr/bin/rbenv exec bundle install
/usr/bin/rbenv exec bundle install
rbenv exec bundle install
bundle install
So I can't figure out what context RubyMine is using to run this command. It's clear from the error message that the GEM_PATH is incorrect, causing RubyMine to look in the wrong place for bundler, but I don't know where it's getting this configuration. If I bring up the "RubyGems Environment" view in RubyMine I get:
RUBYGEMS VERSION: 2.7.3
RUBY VERSION: 2.5.0 (2017-12-25 patchlevel 0) [x86_64-linux]
INSTALLATION DIRECTORY: /home/brad/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0
USER INSTALLATION DIRECTORY: /home/brad/.gem/ruby/2.5.0
RUBY EXECUTABLE: /home/brad/.rbenv/versions/2.5.0/bin/ruby
EXECUTABLE DIRECTORY: /home/brad/.rbenv/versions/2.5.0/bin
SPEC CACHE DIRECTORY: /home/brad/.gem/specs
SYSTEM CONFIGURATION DIRECTORY: /home/brad/.rbenv/versions/2.5.0/etc
RUBYGEMS PLATFORMS:
ruby
x86_64-linux
GEM PATHS:
/home/brad/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0
/home/brad/.gem/ruby/2.5.0
(...)
SHELL PATH:
/home/brad/.rbenv/versions/2.5.0/bin
/usr/lib/rbenv/libexec
/home/brad/.rbenv/plugins/ruby-build/bin
/home/brad/.rbenv/plugins/rbenv-gemset/bin
/home/brad/.rbenv/plugins/rbenv-binstubs/bin
(...rest of PATH...)
----------------------
IDE: RubyMine 2018.2.4, build #RM-182.4505.55
OS: Linux 4.15.0-38-generic[amd64]
Java: 1.8.0_152-release-1248-b8
RubyMine SDK Environment:
Sdk: rbenv: 2.5.0
Sdk Version: ver.2.5.0p0 ( revision 61468) p0
Ruby Interpreter: /home/brad/.rbenv/versions/2.5.0/bin/ruby
RVM Sdk: Rbenv sdk, gemset nullSdk Language Level: 2.5
Sdk Load Path:
~/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib
~/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0
~/.rbenv/versions/2.5.0/lib/ruby/site_ruby/2.5.0/x86_64-linux
~/.rbenv/versions/2.5.0/lib/ruby/site_ruby
~/.rbenv/versions/2.5.0/lib/ruby/vendor_ruby/2.5.0
~/.rbenv/versions/2.5.0/lib/ruby/vendor_ruby/2.5.0/x86_64-linux
~/.rbenv/versions/2.5.0/lib/ruby/vendor_ruby
~/.rbenv/versions/2.5.0/lib/ruby/2.5.0
~/.rbenv/versions/2.5.0/lib/ruby/2.5.0/x86_64-linux
~/.local/share/JetBrains/Toolbox/apps/RubyMine/ch-0/182.4505.55/rubystubs25
Sdk Gem paths:
~/.gem/ruby/2.5.0/gems
~/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/bundler/gems
~/.bundle/ruby/2.5.0/gems
~/.bundle/ruby/2.5.0/bundler/gems
~/.gem/ruby/2.5.0/bundler/gems
~/.rbenv/versions/2.5.0/lib/ruby/gems/2.5.0/gems
(full list of gems used for project)
So I think that last bit - "Sdk Gem paths" - might be the problem point, but I don't see any way to configure it.
I'm also already aware of the YouTrack issue "Rubymine 2018.2 release does not take $GEM_HOME environment variable" and don't think it's quite what's happening here. It also claims to be fixed in 2018.3 EAP1, so I installed 2018.3 EAP7 but am still seeing this problem.
I got things working! By signing out and back in. :facepalm:
To be specific, I think the key steps were
Move the $(rbenv init -) step from my .zshrc up to my .zshenv and/or to .profile
Signing out and back in.
The key insight was noticing that ~/.rbenv/shims was missing from the RubyMine Gem Environment despite showing up in both interactive and login shells (in and out of RubyMine), and realizing that while new shells were picking up my .profile changes, RubyMine itself was probably inheriting its environment variables from my session and I'd need to log out/in to to pick up the changes.
I now see ~/.rbenv/shims in my RubyMine Gem Environment, and both the Bundler Install command and my run configurations are working again.
Thank you Casper for pointing me in the right direction!
Been where you are before a bunch of times.
Under the list of scripts you can run, click "Edit Configurations". Should be in the main toolbar.
Double check that you have "Run the script in context of bundle (bundle exec)" checked on the bundler tab. This is SUPER important and is not checked by default. Make sure you check for any rake, rails or irb configurations.
Keep in mind that the run configuration is where you can override the settings for the project. It will create all kinds of problems if this is not set appropriately.
Hope this helps! Bit me a bunch of times.
I am on a VM (Lucid 64b) with a system Ruby version of 1.9.3p0.
I have a Ruby script that creates a .deb file -- The script needs to use Ruby 1.8.7 which I have installed in /foo/ruby/1.8.7.
There is an existing Gemfile to be used with Bundler
I can't use RVM and I can't install gems at the system level.
My .bashrc includes (and has been sourced)
export PATH=$PATH:/foo/ruby/1.8.7/bin
but ruby -v still gives me
ruby 1.9.3p0 (2011-10-30) [x86_64-linux]
Questions
How can I change the Ruby version for my user to use Ruby 1.8.7?
I've run: bundle install --path vendor/bundle
So in that directory (actually ./vendor/bundle/ruby/1.8/cache/gems) are all the gems I need but, when I run the Ruby script it doesn't find the required gems. I run the script like so /foo/ruby/1.8.7 script_to_gen_deb_file.rb
How can I get ruby to see/use the bundled gems?
Update
I was able to solve it. I needed to use
/foo/ruby1.8.7/bundle exec /foo/ruby1.8.7/ruby script_to_gen_deb_file.rb
I had tried this before, but I got an unrelated error and believed there was an environment problem.
Change your path so the special ruby gets precedence?
export PATH=/foo/ruby/1.8.7/bin:$PATH