rbenv is not initialized properly from automatic deployment - ruby

I am writing app for deployment. I have working rbenv environment on Debian 10. For all users, rbenv is initalized properly, so in project directories proper ruby version is used.
But when I try to run from web app using Kernel.system or just ``, it fails, it is used Ruby version of my web-app. I am trying to initalize it but in $PATH is still bad version.
If I use /var/www/.rbenv/bin/rbenv local then ruby -v prints proper version, but mina deployment fails trying to load gems from local vendor directory of web app project.
When I do this from padrino console usning system():
/var/www/.rbenv/bin/rbenv local && ruby -v
It returns
"2.6.5\nruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-linux]\n"
So rbenv local works fine but another command uses bad ruby version.
Please is there any way to initialize proper version?
EDIT: Answers to questions.
It is web app for deploying on local server of another ruby apps, we have a lots of versions. Web app is running (just this app) on Ruby 3.0.0. I am executing command inside directory of app which I want to deploy (Ruby 2.6.5) using mina, but it failed.
which ruby from padrino console
/var/www/.rbenv/versions/3.0.0/bin/ruby\n
And PATH
=> "/var/www/production/deploy/releases/77/vendor/bundle/ruby/3.0.0/bin:/var/www/.rbenv/versions/3.0.0/bin:/var/www/.rbenv/libexec:/var/www/.rbenv/plugins/ruby-build/bin:/var/www/.rbenv/plugins/rbenv-vars/bin:/var/www/.rbenv/shims:/var/www/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\n"
As you can see, it is 3.0.0.
When I try to run command in kernel system this
cd /var/www/deploy/build/project_to_be_deployed && mina deploy it fails because it tries to use ruby 3 instead of 2.6.5, if I try to switch using rbenv using rbenv local or changing value of RBENV_VERSION it shows me proper 2.6.5 but everyr command is executed under 3.0.0
Maybe I am explaining poorly. Every command is runned from ruby code, using system() call. On bash everything works fine! The problem is I think in the forking of bash or loading the environment during execution of command from ruby

Related

Can't run ruby command on windows 10

Recently I am trying to install Ruby on my Windows 10. After the installation process whenever I am trying to run any ruby command such as to check the version of Ruby, I command ruby -v and I got Access denied notifications.
For better purpose I am giving the screenshot of the problem I am facing:
PS: I am using rubyinstaller-2.4.1-2-x64 to install Ruby.

Jenkins won't recognize local commands

I'm attempting to integrate my Ruby/Cucumber/Appium test framework with our Jenkins environment.
On the local machine I have installed RVM to utilize ruby 2.4, the newest appium, cucumber, and I'm attempting to use the already-installed ruby gems for my jenkins jobs.
How do I get the Jenkins shell to utilize my local RVM instance? I don't want to have to install rvm, cucumber, and appium every time I run a job.
I have already attempted to add environment variables in the Jenkins settings but it still does not recognize my commands.
Note my admin has deleted the automatically generated jenkins user.
you probably want something like this in "Execute shell":
#!/bin/bash
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
rvm use 2.4
bundle install
bundle exec rake
you mention that your jenkins user is gone. the above assumes that there is an rvm setup in the $HOME directory of the user running your builds, so if that's not certain, or you don't know what user is executing your builds, you probably want to start there, echo $USER, and so on, and see if rvm works for that user outside of a jenkins build.

Ruby Rake, Jenkins gem not included

We are currently moving our install of Jenkins from one server to another. Someone else set up Jenkins originally and I am running into difficulties setting it up on the new server (and they aren't here to ask about it)!
Basically it fails on this line:
require 's3'
I believe what it is trying to do is import the amazon sdk. I installed this by doing a
gem install s3
Which worked, but it still can't seem to recognise it as there and include it.
I installed ruby with RVM, and have put everything on PATH (on the server and on Jenkins)
Ruby is run through Jenkins with the rake plugin.
Maybe I configured the PATH wrongly?
Any suggestions would be great, thanks!

Upgrading Git Bash to run newly downloaded ruby 2.0.0

I'm on a Windows machine, so unfortunately I can't use RVM, which would make this super easy.
I previously downloaded Rails and Ruby on a new Windows machine. Rails 4.0.3 and Ruby 1.9.3. For some reason, the package I installed didn't install the new version of ruby. So I just went to http://rubyinstaller.org/downloads/ and downloaded Ruby 2.0.0. If I browse to my Apps to access the Start Command Prompt with Ruby, the version is 2.0.0 (ruby -v). But I use Git Bash, http://git-scm.com/downloads, as my Command Line. Right now, the current ruby version is still 1.9.3 in my Git Bash window. How do I update it to use the newly downloaded Ruby 2.0.0???
Thanks for the help.
Issuing
$ which ruby
will tell you which of the two ruby executables GIT Bash wants to use.
For situations where it is necessary to have two versions of Ruby, it's possible to select one or other for general use using the PATH environment variable.
The order of paths in the Bash $PATH environment variable is important - if the path for your ruby 1.9.3 executable appears before the path for your ruby 2.0.0 executable, then the interpreter will use the 1.9.3. So, for example;
Ruby 1.9.3 is in /c/Software/Ruby/1.9.3/ruby.exe
Ruby 2.0.0 is in /c/Program Files/Ruby/2.0.0/ruby.exe
And your PATH variable is as follows;
$ echo $PATH
/c/GIT/bin:.:/c/Software/Ruby/1.9.3/:/c/Program Files/Ruby/2.0.0/
Then you would need to re-order your PATH variable so that the 2.0.0 path comes before the 1.9.3 path. Find your .bashrc file (by default in your home directory) and examine any PATH definitions, e.g.;
PATH=$PATH:/c/Program Files/Ruby/2.0.0/
And modify so that your 2.0.0 path has precedence
PATH=/c/Program Files/Ruby/2.0.0/:$PATH
You can issue this command on the command line also, making sure to do
$ export $PATH
once you've made your changes. Otherwise you'll need to source .bashrc or start a new shell. GIT Bash should then pick up the correct executable.
An alternative is to create aliases or symbolic links for each executable which specifies their version, such that typing ;
$ ruby193
Executes the 1.9.3 ruby and
$ ruby200
executes the 2.0.0 version.
Aliasing is as follows;
$ alias ruby193=/c/Software/Ruby/1.9.3/ruby.exe
Linking is as follows;
$ ln -s /c/Software/Ruby/1.9.3/ruby.exe /c/GIT/bin/ruby193
Aliases you use frequently should be put in .bashrc .

Installing Ruby on Mac 1.9.2, still getting 1.8.7 even though path changed

I'm on a Mac running 10.6.4 Snow Leopard, and apparently ruby comes ready to go. But I'm new to Ruby, trying to learn the Rails framework, and so i decided to install the latest version 1.9.2. I followed the instructions here, but after I compile and install, when I run ruby -v I'm still getting 1.8.7. Anyone can help a noob out?
When I use which ruby I am getting usr/local/bin/ruby, so the path has changed and is correct.
UPDATE:
It seems I was having issues because I was using two login files to set my path (.bash_login and .profile). You can only use one, and the first one that exists and is readable will be used. I eventually switched to RVM and used .bash_login to load RVM into shell.
Well, the sw isn't lying to you. So something is not as you expect.
Try /usr/local/bin/ruby -v and see what version it is.
Added: Also, try locate ruby|more to see where the ruby files are on your system.
You may need to change your path to use your newly installed copy of ruby.
Added more: did you add the Path to your ~/.profile file as the instructions tell you to do in step 1?
Did you restart your terminal session after changing the ~/.profile file? (Quit and restart terminal.)

Resources