Mac Rspec install fail: -bash: rspec: command not found - macos

I am a newbie and been stuck with this for 2 days; I am about to go crazy.
I am starting to learn Ruby and we got to Rspec.
I installed Rspec with gem install rspec and everything goes ok, but when I execute which rspec I get nothing returned.
When I execute "gem which rspec" I get:
/usr/local/lib/ruby/gems/3.0.0/gems/rspec-3.10.0/lib/rspec.rb
My $PATH is:
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
export PATH="/usr/local/opt/openssl/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
alias laptop='bash <(curl -s https://raw.githubusercontent.com/monfresh/laptop/master/laptop)'
export PATH="$HOME/.bin:$PATH"
export PATH="/usr/local/opt/ruby/bin:$PATH"
export PATH="/usr/local/lib/ruby/gems/3.0.0/gems/rspec-3.10.0/lib:$PATH"
And "which ruby" throws:
/usr/local/opt/ruby/bin/ruby
I took a look at these two posts but had no luck with them Post 1
,
Post 2
Any help will be really appreciated!

Related

Script to take a backup of all git repo's and set a cronjob using the same script

I Want to set a script and use a cronjob to take a backup of all the repositories.
FYI...
RVM Version: 1.20.13, Ruby Version: 1.9.3p429, Gem Version: 1.8.25, Bundler Version:1.3.5, Rake Version: 10.0.4, GitLab information Version: 5.3.0
I Tried the methods below, but they didn't work. Please help me to set the required cronjob. When I execute the commands manually they were working fine.
Method 1:
#!/bin/bash
cd /home/git/gitlab/
bundle exec rake gitlab:backup:create RAILS_ENV=production
Error:
bundle: command not found
Method 2:
#!/bin/sh
cd /home/git/gitlab/
bundle exec rake gitlab:backup:create RAILS_ENV=production
Error:
/bin/sh: bundle: command not found
Method 3:
10 10 * * * cd /home/git/gitlab && PATH=$PATH:$/home/git/.rvm/gems/ruby-1.9.3-p429/bin:/home/git/.rvm/gems/ruby-1.9.3-p429#global/bin:/home/git/.rvm/rubies/ruby-1.9.3-p429/bin:/home/git/.rvm/bin::/home/git/.rvm/rubies/ruby-1.9.3-p429/.irbrc bundle exec rake gitlab:backup:create RAILS_ENV=production CRON=1 >> /tmp/git_bck.log 2>&1
Error:
/home/git/.rvm/gems/ruby-1.9.3-p429#global/bin/ruby_noexec_wrapper:7:in `require': no such file to load -- rubygems (LoadError) from /home/git/.rvm/gems/ruby-1.9.3-p429#global/bin/ruby_noexec_wrapper:7
you need to do 2 things:
1) recreate the same environment you have in the command line. For this run env in the command line and after that run env in a cron and output to a shell, compare the 2 of them
2) source rvm in (look in your .bashrc or whatever rc your shell has).
These 2 things should allow you to run the script from the cron. You can place them in the beging of the script.
Problem solved :
In .bashrc , added
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
export GIT_HOME=/home/git/git
export JAVA_HOME=/home/git/jdk
export PATH=$PATH:$GIT_HOME/bin:$JAVA_HOME/bin
source /home/git/.rvm/environments/default
In .bash_profile, added
PATH=$PATH:$HOME/bin
export PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
FYI..
cat /home/git/.rvm/environments/default
export PATH ; PATH="/home/git/.rvm/gems/ruby-1.9.3-p429/bin:/home/git/.rvm/gems/ruby-1.9.3-p429#global/bin:/home/git/.rvm/rubies/ruby-1.9.3-p429/bin:/home/git/.rvm/bin:$PATH"
export rvm_env_string ; rvm_env_string='ruby-1.9.3-p429'
export rvm_path ; rvm_path='/home/git/.rvm'
export rvm_ruby_string ; rvm_ruby_string='ruby-1.9.3-p429'
unset rvm_gemset_name
export RUBY_VERSION ; RUBY_VERSION='ruby-1.9.3-p429'
export GEM_HOME ; GEM_HOME='/home/git/.rvm/gems/ruby-1.9.3-p429'
export GEM_PATH ; GEM_PATH='/home/git/.rvm/gems/ruby-1.9.3-p429:/home/git/.rvm/gems/ruby-1.9.3-p429#global'
export MY_RUBY_HOME ; MY_RUBY_HOME='/home/git/.rvm/rubies/ruby-1.9.3-p429'
export IRBRC ; IRBRC='/home/git/.rvm/rubies/ruby-1.9.3-p429/.irbrc'
unset MAGLEV_HOME
unset RBXOPT
In crontab script :
cd /home/git/gitlab/
source $HOME/.bash_profile
source $HOME/.bashrc
bundle exec rake gitlab:backup:create RAILS_ENV=production

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.

Require statement not working in ruby from bash

I'm trying to get ttscoff's TaskPaper to Markdown ruby script https://gist.github.com/511174 working. However, I use rvm, which seems to present some challenges.
-rjcode is a no-longer needed Unicode flag and -Ku is another encoding flag I can probably ignore.
I found instructions for adding rvm as a function to your script, but the script still errors as soon as it hits require ftools.
What I added is:
#!/usr/bin/env bash
# TaskPaper to Markdown converter
# Usage: tp2md.rb filename.taskpaper > output.md
# Load RVM into a shell session *as a function*
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
# First try to load from a user install
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
# Then try to load from a root install
source "/usr/local/rvm/scripts/rvm"
else
printf "ERROR: An RVM installation was not found.\n"
fi
# Configure ruby and gemset
rvm ruby-1.9.2-p290#global
ruby <<-rb
puts "Hello!"
rb
Hello! outputs fine, but I get the following errors afterwards:
require: command not found
infile: command not found
prevlevel: command not found
begin: command not found
syntax error near unexpected token `('
` file = File.new(infile, "r")'
My problem seems to be related to the gem not getting pulled in. I've uninstalled ftools and reinstalled with rvm, but still no dice. Thankful for any help!
Your telling ruby to load the 'b' library.
-r library Causes Ruby to load the library using require. It is useful when using -n or -p.
This should work.
ruby -r ftools <<rb
puts "Hello!"
rb

How do I change my Ruby version using RVM?

I am not able to switch the current Ruby version:
➜ ~ rvm list
rvm rubies
ruby-1.9.2-p290 [ x86_64 ]
ruby-1.9.3-p0 [ x86_64 ]
➜ ~ rvm use ruby-1.9.3-p0
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
Fixed it. I needed to add:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM
to .zshrc
This happened to me too. I had:
export PATH=~/.rvm/bin:$PATH
Added in my .bashrc.
All I had to do was add another
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
to the same file and it worked!
Of course, you have to restart your terminal after that.
Your shell doesn't know about the RVM function. After you install it, it tells you how to take care of this. Or go to the install page on the RVM site and check out the section titled "2. Load RVM into your shell sessions as a function"
Run this once to add the line that loads rvm into your ~/.bash_profile:
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
or manually add it yourself. (Note that on some systems, you will want to put it in other places, for example on my system, Mac OSX Lion, I put it in ~/.profile)
(Kubuntu 11.10) The ~/.bash_profile is now called ~/.profile
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.profile
source ~/.profile
rvm info # And now the fields display
To Change the Default Version of ruby:
In Ubuntu 11.10
please change your GNOME terminal setting :
Go to Terminal and then follow the following instructions:
1. Edit > Profile Preferences
2. Open Title and Command Tab
3. Check Run Command as a login Shell
4. Restart terminal
Run this command on terminal:
rvm --default use ruby_Version
To add all RVM functionality to your .bash_profile you should use following command:
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
After that you should reload the current shell or open a new terminal session and type the following command to reload .bash_profile:
source .bash_profile
The above solution will only work, if RVM is installed for the current user. A more general solution would use the RVM path variable:
# The following code loads RVM as user or system install:
[[ -s "$rvm_path/scripts/rvm" ]] && . "$rvm_path/scripts/rvm"
I just had to invoke source ~/.bash_profile
On a clean install of Ubuntu 12.04 I ran into the same issue. The RVM installer creates or appends to a file called ~/.bash_login the necessary bit of code to avoid the original problem:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
However this does not seem to get invoked. Adding it to ~/.bashrc resolved the issue for me.
Installing RVM, See here http://octopress.org/docs/setup/rvm/
In my case on Ubuntu, the entry in ~/.bashrc had:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && ."$HOME/.rvm/scripts/rvm" # BAD
instead of:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # WORKING
Notice the missing space between . and "$HOME.
Also, if this is the problem, you should also be noticing an error on top when you start your terminal.
I had a global install of RVM, which runs /etc/profile.d/rvm.sh. However, that script requires the BASH_VERSION or ZSH_VERSION to be set. I was running from crontab, which uses "sh".
I created a wrapper script that uses /bin/bash to source /etc/profile.d/rvm.sh.
You need to change your terminal emulator preferences to allow login
shell. Sometimes it is required to use /bin/bash --login as the
command.

RVM system-wide install script url broken -- what is replacement?

My RVM system-wide installation scripts are broken, both in the form of Linode StackScripts and Chef-solo Recipes.
Per the instructions on the RVM website, my scripts execute the following commands as root to install RVM on a system-wide basis:
echo "Installing RVM system-wide" >> $logfile
bash < <( curl -L http://bit.ly/rvm-install-system-wide )
cat >> /etc/profile <<'EOF'
# Load RVM if it is installed,
# first try to load user install
# then try to load root install, if user install is not there.
if [ -s "$HOME/.rvm/scripts/rvm" ] ; then
. "$HOME/.rvm/scripts/rvm"
elif [ -s "/usr/local/rvm/scripts/rvm" ] ; then
. "/usr/local/rvm/scripts/rvm"
fi
EOF
source /etc/profile
The key piece above is the url http://bit.ly/rvm-install-system-wide. As of today, 3/24/2011, this url no longer in service. It results in a GitHub 404 error.
The following url on the RVM website used to contain the instructions for the system-wide install: http://rvm.beginrescueend.com/deployment/system-wide/. However, that url now redirects to the RVM homepage.
In the interests of getting RVM system-wide installation scripts to work again, what are the new instructions?
Here is my fix to install the last working version before he major change:
bash <( curl -L https://github.com/wayneeseguin/rvm/raw/1.3.0/contrib/install-system-wide ) --version '1.3.0'
This is working for me now in production. Good luck!
UPDATE
Also, if you are using the chef cookbook from https://github.com/fnichol/chef-rvm or something similar, you can use the following options:
:rvm => {
:system_installer_url => "https://github.com/wayneeseguin/rvm/raw/1.3.0/contrib/install-system-wide",
:version => "1.3.0"
}
Just received the following answer from the lead developer, wayneeseguin, on #rvm:
[12:53] "the author" merged it into the ain installer
[12:53] so you should be doing
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
# http://rvm.beginrescueend.com/rvm/install/
[12:53] the code has just changed and the documentation hasn't caught up
[12:53] for both root and user installs
It is true that RVM 1.5.1 will successfully install into /usr/local/bin just by installing as root. However, for some reason, all the existing Chef and Puppet provisioning scripts that are in use today do not appear to survive this version bump. This is unfortunate, as Wayne E. Seguin has made clear that RVM below version 1.5.0 will not be supported.
That said, we need our systems to work today. In order to continue to use RVM 1.3.0, which the existing scripts support, you need to replace the following line:
bash < <( curl -L http://bit.ly/rvm-install-system-wide )
With the following line (found by phlipper):
bash -c "bash <( curl -L https://github.com/wayneeseguin/rvm/raw/1.3.0/contrib/install-system-wide ) --version '1.3.0'"

Resources