I am trying to work with a web app made by someone else. I cloned that repo and when I cd'ed into it, the .rvmrc executed. But I am getting the following error in it:
: command not found
: command not found
: command not found
: command not found
-bash: /home/sleepingdragon/Desktop/sharedcab/main-apps/ytaxi-apps/yTaxi/.rvmrc: line 22: syntax error in conditional expression
-bash: /home/sleepingdragon/Desktop/sharedcab/main-apps/ytaxi-apps/yTaxi/.rvmrc:'line 23: syntax error near `]]
-bash: /home/sleepingdragon/Desktop/sharedcab/main-apps/ytaxi-apps/yTaxi/.rvmrc:'line 23: ` && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
The .rvmrc file is this:
#!/usr/bin/env bash
# This is an RVM Project .rvmrc file, used to automatically load the ruby
# development environment upon cd'ing into the directory
# First we specify our desired <ruby>[#<gemset>], the #gemset name is optional,
# Only full ruby name is supported here, for short names use:
# echo "rvm use 1.9.3" > .rvmrc
environment_id="ruby-1.9.3-p194#ytaxi"
# Uncomment the following lines if you want to verify rvm version per project
# rvmrc_rvm_version="1.14.2 (stable)" # 1.10.1 seams as a safe start
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
# return 1
# }
# First we attempt to load the desired environment directly from the environment
# file. This is very fast and efficient compared to running through the entire
# CLI and selector. If you want feedback on which environment was used then
# insert the word 'use' after --create as this triggers verbose mode.
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
if [[ $- == *i* ]] # check for interactive shells
then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
fi
else
# If the environment file has not yet been created, use the RVM CLI to select.
rvm --create use "$environment_id" || {
echo "Failed to create RVM environment '${environment_id}'."
return 1
}
fi
# If you use bundler, this might be useful to you:
# if [[ -s Gemfile ]] && {
# ! builtin command -v bundle >/dev/null ||
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
# }
# then
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
# gem install bundler
# fi
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
# then
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
# fi
I have not worked with .rvmrc before and am a Rails noob. Could you help me find the error?
Just create .ruby-version file containing
ruby-1.9.3-p194#ytaxi
and delete the .rvmrc file.
You are using minimal version of .rvmrc which also is buggy, you could either fix it:
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" &&
-s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
and you can switch to the new .ruby-version file:
rvm get stable
rvm rvmrc to ruby-version
Related
If you have simple shell command binstubs in the local bin directory of a Rails project (e.g. not generated by or running a gem), rbenv seems to have trouble executing them. For example, #tpope's heroku binstubs generate a binstub named production in the local bin directory:
#!/bin/sh
HEROKU_APP=myapp-production HKAPP=myapp-production exec "${HEROKU_COMMAND:-heroku}" "$#"
After an rbenv rehash, the production command shows up in the ~/.rbenv/shims directory looking something like this:
#!/usr/bin/env bash
set -e
[ -n "$RBENV_DEBUG" ] && set -x
program="${0##*/}"
if [ "$program" = "ruby" ]; then
for arg; do
case "$arg" in
-e* | -- ) break ;;
*/* )
if [ -f "$arg" ]; then
export RBENV_DIR="${arg%/*}"
break
fi
;;
esac
done
fi
export RBENV_ROOT="/Users/Username/.rbenv"
exec "/usr/local/Cellar/rbenv/0.4.0/libexec/rbenv" exec "$program" "$#"
So executing which production gives you:
/Users/Username/.rbenv/shims/production
But executing rbenv which production (or trying to run the command) gives you:
rbenv: production: command not found
I'm new to rbenv so maybe I missed a config step?
Apparently project-specific binstubs in Rails projects should be kept outside of the local bin/ directory since those are primarily for application scripts. So one approach (i.e. that used by the rbenv-binstubs plugin) is to keep local binstubs separate and override rbenv shims with that local binstub directory (e.g. .bundle/bin). So by using the plugin you might see this result from which production:
/Users/Username/.rbenv/shims/production
But if you move the production binstub to .bundle/bin, then rbenv which production should yield:
{PROJECT_ROOT}/.bundle/bin/production
I'm trying to deploy an experimental Rails app within my enterprise. Everything here is setuo for Java development so I'm having to break new ground to gain acceptance for Rails in the company.
I need to use Jenkins CI (v. 1.580) to deploy my Rails 4.1.4 app (ruby-2.1.2) on a CentOS (release 5.9) staging server here in the office, as a proof of concept before my app will be allowed near a production server.
I've installed the following plugins in Jenkins and restarted: Hudson Ruby Plugin, rvm, Rake plugin, ruby-runtime, RubyMetrics plugin for Jenkins, GIT client plugin, GIT plugin, GitHub API Plugin, GitHub plugin
The Jenkins build seems to be failing during an RVM initialisation script, output below.
My Jenkins .bashrc file looks like this:
#/var/lib/jenkins/.bashrc
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
And .rvmrc:
#/var/lib/jenkins/.rvmrc
export rvm_trust_rvmrcs_flag=1 # always trust project .rvmrc
export rvm_install_on_use_flag=1 # auto install rubies
export rvm_gemset_create_on_use_flag=1 # auto install gemsets
I've tried nuking RVM and reinstalling using the multi-user instructions and have ensured that my jenkins user is a member of the rvm group.
My build script looks like:
source ~/.bashrc # Loads RVM
cd . # Loads the RVM environment set in the .rvmrc file
# set env vars
#export GEM_PATH=/usr/local/lib/ruby/gems/1.2/gems
#export CI_REPORTS=results
export RAILS_ENV=test
#cp config/database.yml.example config/database.yml
# creates a database.yml
bundle install # Installs gems
rake db:schema:load # Loads all the database schema
rake # Runs RSpec tests
Here's the complete Console Output from Jenkins
Started by user Pete
Building in workspace /var/lib/jenkins/jobs/MerchantManager/workspace
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url https://github.com/***/epgDataPoc # timeout=10
Fetching upstream changes from https://github.com/***/epgDataPoc
> git --version # timeout=10
using .gitcredentials to set credentials
> git config --local credential.helper store --file=/tmp/git5734173224303904567.credentials # timeout=10
> git fetch --tags --progress https://github.com/***/epgDataPoc +refs/heads/*:refs/remotes/origin/*
> git config --local --remove-section credential # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 8bced4d8fecd4135bcb4868aa4011e140adf46d3 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 8bced4d8fecd4135bcb4868aa4011e140adf46d3
> git rev-list 8bced4d8fecd4135bcb4868aa4011e140adf46d3 # timeout=10
[workspace] $ /bin/bash -xe /tmp/hudson1400066644804618273.sh
+ source /var/lib/jenkins/.bashrc
++ [[ -s /var/lib/jenkins/.rvm/scripts/rvm ]]
++ source /var/lib/jenkins/.rvm/scripts/rvm
+++ builtin test -n '3.2.25(1)-release' -o -n ''
+++ case "`uname`" in
++++ uname
++++ command ps -p 29628 -o ucomm=
++++ ps -p 29628 -o ucomm=
+++ __shell_name=bash
+++ case "$__shell_name" in
+++ unset __shell_name
+++ __rvm_has_opt posix
+++ [[ -n '' ]]
+++ [[ -n 3.2.25(1)-release ]]
+++ [[ :braceexpand:errexit:hashall:interactive-comments:xtrace: =~ :posix: ]]
+++ return 1
+++ export HOME rvm_prefix rvm_user_install_flag rvm_path
+++ HOME=/var/lib/jenkins
+++ [[ -n '' ]]
++++ umask
+++ export rvm_stored_umask=0022
+++ rvm_stored_umask=0022
+++ (( 0 == 0 ))
+++ rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
+++ [[ -n '' ]]
+++ for rvmrc in '"${rvm_rvmrc_files[#]}"'
+++ [[ -f /etc/rvmrc ]]
+++ GREP_OPTIONS=
+++ command grep '^\s*rvm .*$' /etc/rvmrc
Build step 'Execute shell' marked build as failure
Publishing rails stats report...
hudson.model.StreamBuildListener#1bb557c8
Finished: FAILURE
I fixed this by trial and error:
By swapping these lines in .bashrc:
#/var/lib/jenkins/.bashrc
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
And making the following changes to my build script:
#!/bin/bash
source $JENKINS_HOME/.bashrc
rvm use ruby-2.1.2#datapoc
# Set "fail on error" in bash
set -e
# Do any setup
# e.g. possibly do 'rake db:migrate db:test:prepare' here
#cp config/database.example.yml config/database.yml
bundle install
rake db:schema:load
rake
I want to run bundle install on my Jenkins server in the context of a given RVM Ruby Installation.
When I sign in via SSH it all works fine:
which bundle
# /Users/me/.rvm/gems/ruby-2.1.0#global/bin/bundle
ruby -v
# ruby 2.1.0p0 ...
But when I do this via Jenkins I get this:
which bundle
# /usr/bin/bundle
So I added source ~/.bash_profile to the top of my script which should load the RVM context but for this I get the following output and the path of bundle is still wrong:
+ source /Users/me/.bash_profile
++ [[ -s /Users/me/.profile ]]
++ source /Users/me/.profile
+++ PATH=/usr/bin:/bin:/usr/sbin:/sbin:/Users/me/.rvm/bin
++ [[ -s /Users/me/.rvm/scripts/rvm ]]
++ source /Users/me/.rvm/scripts/rvm
+++ __rvm_has_opt posix
+++ [[ -n '' ]]
+++ [[ -n 3.2.51(1)-release ]]
+++ [[ :braceexpand:errexit:hashall:interactive-comments:posix:xtrace: =~ :posix: ]]
+++ return 0
+ which bundle
/usr/bin/bundle
Now how do I tell Jenkins to always load the RVM Environment. Thanks :)
When I run a shell script in Jenkins, I do something like
#!/bin/bash
echo '##################### BUNDLE/MIGRATION #####################'
source ~/.bashrc
rvm use 2.1#gemset
bundle install
bundle exec rake db:schema:load RAILS_ENV=test
bundle exec rake db:test:prepare
I my .bashrc I have the lines
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
PATH=$PATH:$HOME/.rvm/bin
I do not know if this is the state of the art, but it works :-)
Try this: rvm 2.1 do which bundle
After installing rvm when i run this
source $HOME/rvm/scripts/rvm
i get error
-bash: /root/rvm/scripts/rvm: No such file or directory
reference: Problem deploying Ruby+RVM and daemontools
I found the answer but looking at the rvmsudo script installed with
rvm, here is a working run script:
#!/bin/sh
# redirect stderr to stdout
exec 2>&1
cd /app
# load rvm
. /usr/local/rvm/scripts/rvm
# select ruby version for this application
rvm use 1.9.1
# # depending on your configuration you may need to provide the absolute path to rvm, like that:
# /usr/local/bin/rvm use 1.9.1
# build the exec command line preserving the rvm environment
command="exec sudo -u app_user /usr/bin/env PATH='$PATH'"
[[ -n "${GEM_HOME:-}" ]] && command="${command} GEM_HOME='$GEM_HOME' "
[[ -n "${GEM_PATH:-}" ]] && command="${command} GEM_PATH='$GEM_PATH' "
# this is where your real command line goes
command="${command} ruby main.rb"
# run the application
eval "${command}"
Try source ~/.rvm/scripts/rvm. Exit out of your current shell and then try again it should work.
I just went through the RVM install.
I did this command:
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
and everything ran fine. Then in my user home directory, in .bash_profile I added
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Then I started a new shell just to be sure. And then I tried
rvm
and got the error that
No command 'rvm' found
Any ideas why that might happen?
maybe it is because .bash_profile only runs on login, if you run a new shell it only executes .bashrc
You could test using
> bash -l
Did you see the "Troubleshooting your Install" section on this page.
It mentions that you need to remove return from your .bashrc. I often forget to do this on a fresh ubuntu install.
The example they give for ubuntu is to change this:
[ -z "$PS1" ] && return
# Some code here... e.g.
export HISTCONTROL=ignoreboth
to this:
if [[ -n "$PS1" ]]; then
# Some code here... e.g.
export HISTCONTROL=ignoreboth
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session