"rvm use --install" broken in Jenkins, "uname: command not found" - ruby

This is a snippet from a Jenkins job run that needs rvm 1.9.3.. I have no idea why the PATH is not being looked at. From this build the PATH environment variable looks correctly set as PATH="/usr/java/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" (as set in /etc/environment), HOME="/scratch" and SHELL="/bin/sh", so I'm mystified by this.
$ bash -c " source ~/.rvm/scripts/rvm && rvm use --install --create ruby-1.9.3 && export > rvm.env"
/scratch/.rvm/scripts/rvm: line 12: uname: command not found
/scratch/.rvm/scripts/rvm: line 15: ps: command not found
bash: rvm: command not found
I have also attempted the rbenv route but am met with similar errors indicating the absence of $PATH
Also, the Jenkins user belongs to the rvm group.
I send many internets in thanks for any assistance offered!

rvm needs login shell.
I use it like this in my builds:
echo "rvm install 2.2.3" | /bin/bash -l
Works just fine this way.

Related

source /.bash_profile command provide error

I run the command source ~/.bash_profile and get the following error:
$ source ~/.bash_profile
-sh: /Users/chaklader/.sdkman/contrib/completion/bash/sdk: line 37: syntax error near unexpected token `<'
-sh: /Users/chaklader/.sdkman/contrib/completion/bash/sdk: line 37: ` done < <(curl --silent "${SDKMAN_CANDIDATES_API}/candidates/all")'
The login shell that I use is bin/sh:
Whats the issue here and how to solve it?
This is how I solved the issue with the provided steps:
Install Homebrew from the docs on their homepage
Install Git using Homebrew (optional, but nice to have a more up-to-date git)
brew install git
Now install bash:
brew install bash
Add this install of bash to the allowed shells list:
echo '/usr/local/bin/bash' | sudo tee -a /etc/shells;
Homebrew installs things to /usr/local/Cellar/ by default, then symlinks any binaries to /usr/local/bin, so you've now got the latest bash sitting at /usr/local/bin/bash
Finally, change your shell to use this new one:
chsh -s /usr/local/bin/bash
Open a new terminal window/tab, and run these commands to double-check your work:
$ echo $SHELL
/usr/local/bin/bash
$ echo $BASH_VERSION
5.1.8(1)-release
This also solved the issue for running the source ~/.bash_profile whenever I open a new window in the terminal.
Reference:
The answer is from here How do I install Bash >= 3.2.25 on Mac OS X 10.5.8? by user jeffbyrnes

Automatic RVM installation

I am trying to have RVM and ruby installed in an Ubuntu 12 virtual machine without human interaction apart from the password prompts.
I created a shell script to do this that works pretty fine until I need to use RVM itself.
I am using multi-user installation.
#!/bin/bash -l
mainUser=`whoami`
echo "Installing as '${mainUser}'"
echo "Installing git..."
sudo -S apt-get install --yes curl git-core
echo "Installing RVM..."
\curl -L https://get.rvm.io | sudo bash -s stable
echo "Adding ${mainuser} to RVM group..."
sudo adduser $mainUser rvm
newgrp rvm
From here things get weird.. I need to load dvm as a source. I want both my script to have this source and my user's bash_profile / bashrc. Anyway.. I know how to do it manually, but I can't have this done from the script. This is the last code I tried:
. "/usr/local/rvm/bin/rvm"
rvm use ruby-head
rubyVersion=`rvm list | awk '/ruby-head/{print x;print};{x=$0}' | sed -n '/ruby-head/{g;1!p;};h' | awk -F ' ' '{print $1}'`
rubyTest=${rubyVersion}#test
rvm use $rubyTest --create --default
The error I get is this:
test.sh: 7: /usr/local/rvm/bin/rvm: Syntax error: "(" unexpected (expecting "fi")
If I simply try to use the full path, like this:
rvm=/usr/local/rvm/bin/rvm
$rvm use ruby-head
rubyVersion=`$rvm list | awk '/ruby-head/{print x;print};{x=$0}' | sed -n '/ruby-head/{g;1!p;};h' | awk -F ' ' '{print $1}'`
rubyTest =${rubyVersion}#test
$rvm use $rubyTest --create --default
I get this error instead:
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
I am clueless. Why can't I use /usr/local/rvm/bin/rvm?
Is there a way to execute source /etc/profile.d/rvm.sh for this user from the script?
I am not so good at shell script and Linux, so I appreciate any references and examples you could give.
Thanks!
UPDATE
I also tried:
source "/usr/local/rvm/scripts/rvm"
... and all it's variants. Same error: "RVM is not a function".
rvm is actually implemented as a shell function rather than an executable, which is why you can't just call /usr/local/rvm/bin/rvm itself.
Quoting you, "Is there a way to execute source /etc/profile.d/rvm.sh for this user from the script?"
Have you tried doing that? I had a somewhat similar install once where it didn't work properly from crontab (they have instructions on the site for that scenario, but we couldn't make them work), and I had to do almost exactly that -- source part of the profile.d for rvm.
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
Above error is generated when rvm is not running and hence your terminal is not able to recognize it, as it tries to run it as a system command.
You may want to try this to run rvm through your shell script before calling rvm methods:
source ~/.rvm/scripts/rvm
I found out what is causing the issue.
I realised before that I would get errors in the lines with conditions in the script files, so I came across this page:
https://superuser.com/questions/552016/bash-script-not-found
As it happens, I was executing the script with the following command:
sh script.sh
Which means I was getting Dash instead of Bash.
To fix the issue I changed my code to have this:
PATH=$PATH:/usr/local/rvm/bin # Add RVM to PATH for scripting
[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm" # Load RVM function
And then I executed like this:
bash script.sh
And voilĂ ... RVM works again!

Fish shell and rvm - allowing login shell

When I try to use rvm in fish shell, I get this message:
ciembor#ciembor ~> rvm use 1.9.2
RVM is not a function, selecting rubies with 'rvm use ...' will not
work.
You need to change your terminal emulator preferences to allow login
shell. Sometimes it is required to use /bin/bash --login as the
command. Please visit https://rvm.io/integration/gnome-terminal/ for a
example.
I get used to use /bin/bash --login, then rvm and then starting fish from bash. But isn't there more straightforward way? I use xfce4 terminal.
I had the same issue. Download the rvm fish function from GitHub:
curl --create-dirs -o ~/.config/fish/functions/rvm.fish https://raw.github.com/lunks/fish-nuggets/master/functions/rvm.fish
Reference: http://rvm.io/integration/fish
Download the fish functions from GitHub.
curl -L --create-dirs -o ~/.config/fish/functions/rvm.fish https://raw.github.com/lunks/fish-nuggets/master/functions/rvm.fish
And activate the default Ruby manually in your config.fish file:
echo "rvm default" >> ~/.config/fish/config.fish
And you're done
Try look at bash "initialization" files like ~/.bashrc ~/.bash_profile and session "initialization" files ~/.profile /etc/profile* and add rvm related code(something like
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
) to fish "initialization" file ~/.config/fish/config.fish

RVM is not a function even when running command as login shell [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Cannot use RVM-installed Ruby with sudo
I'm running into the same "RVM is not a function..." error when executing the command sudo rvm use 1.9.3 as everyone else, but try as I might, I cannot seem to resolve it. I've read and followed through with all of the common troubleshooting tips, but nothing seems to work...
My System --- OS: Ubuntu 12.10 --- Ruby Version: 1.9.3 --- RVM Version: 1.18.3
I have done the following to try to repair the issue:
Checked the 'Run command as login shell' option in the "Title and Command" tab for Terminal preferences
Added the following code block to ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.zprofile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
if test -f ~/.rvm/scripts/rvm; then
[ "$(type -t rvm)" = "function" ] || source ~/.rvm/scripts/rvm
fi`
Running user$ source ~/.rvm/scripts/rvm and then user$ type rvm | head -n 1 DOES return rvm is a function. But then running sudo rvm use 1.9.3 returns "RVM is not a function"
What else can I do to resolve this issue?
You can not run rvm with sudo, sudo is running a new process which defeats the function approach which can change current running shell environment.

Problem installing RVM

I have executed the commands as prescribed in the instructions at the rvm website but things don't seem to work..
Fetching the code from the git repository runs smoothly but when I try to use
rvm notes
Error:
/usr/local/bin/rvm: line 73: /home/cody/.rvm/scripts/rvm: No such file or directory
flashes in multiple lines and doesn't stop till I hit ctrl+C..
I am running Ubuntu 8.04 and currently I am running ruby 1.9.2..
Sorry, if I am missing out any necessary information. Thanks in advance.
Ack, I didn't mean to post this as a comment on the question. Anyway, if I had to guess, I'd say you installed rvm using sudo or as root. If that is the case, remove it and reinstall without sudo:
sudo rm -rf $HOME/.rvm $HOME/.rvmrc /etc/rvmrc /etc/profile.d/rvm.sh \
/usr/local/rvm /usr/local/bin/rvm
sudo /usr/sbin/groupdel rvm # this might fail, it's not that important
Open new terminal window/tab and make sure rvm is removed:
env | grep rvm
The output should be empty, sometimes it's needed to relogin, after it's empty you can continue:
curl -sSL https://get.rvm.io | bash -s stable
It works perfectly fine installed for the local user.
Ok, for anyone who tried to install RVM using sudo and is now pulling
their hair out trying to get it to install in $HOME/.rvm, here's what
did it for me:
When you installed RVM using sudo, it created a file /etc/rvmrc, which contains the following:
umask g+w
export rvm_path="/usr/local/rvm"
This makes all future attempts at installation (even when not run as sudo)
install into /usr/local/rvm, which is NOT what you want for a single
user installation. So remove /etc/rvmrc and then you can run
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
and it will install properly into $HOME/.rvm
DId you add this line to your ~/.bashrc?
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
I have executed the commands as prescribed in the instructions at the rvm website.
WHICH commands? There are several pages containing instructions to install RVM depending on whether you want a single-user "sandbox" or are installing system-wide for a multi-user system as the administrator.
Because you have RVM in /usr/local, I think you tried to do a system-wide install but didn't get it right. For 99% of us, that is the wrong installation method, and instead you should use the single-user installation, which is simple and puts everything in ~/.rvm.
Either way, be sure to read the entire instructions. And, if doing a single-user install, finish the install with the "Post Install" modifications to ~/.bashrc or ~/.bash_profile for a single-user, then start a new terminal session.
When using the single-user install NEVER use sudo to install gems to a RVM-managed Ruby, even though the instructions for a gem might say to.
Look at the section "Troubleshooting your install" here. Since you are on Ubuntu, you probably need to make further mods to you .bashrc
in .bashrc have you changed the
[ -z "$PS1" ] && return
to
if [[ -n "$PS1" ]]; then
and added this to the end of the file:
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
I just had a similar problem.
It turned out that many files in ~/.rvm/scripts/ and ~/.rvm/src/rvm/scripts/ which obviously should be executable did not have execute permissions. Running a script on both directories to set all files to executable solved that immediate problem.
I have got same problem after installation. Then I restarted terminal and it started working poperly.

Resources