Terminal .bash_profile was messed up. How to revert? - ruby-on-rails

I was following a tutorial on how to setup ruby on rails. http://blog.parsalabs.com/blog/2013/08/27/setting-up-a-ruby-on-rails-4-development-environment-on-a-clean-mac-os-x-installation/
I ran:
$ brew install rbenv
$ touch ~/.bash_profile
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
and now my terminal has stopped working.
$ emacs ~/.bash_profile
-bash: emacs: command not found
when I open a new terminal window. I get the following message:
Last login: Mon Sep 23 23:25:39 on ttys001
-bash: n: command not found
export PATH=/usr/local/bin:/Users/Marcus/.local/bin:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.3/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
-bash: export: `export PATH="/Users/Marcus/.rbenv/shims:${PATH}"
source "/usr/local/Cellar/rbenv/0.4.0/libexec/../completions/rbenv.bash"
rbenv rehash 2>/dev/null
rbenv() {
typeset command
command="$1"
if [ "$#" -gt 0 ]; then
shift
fi
case "$command" in
rehash|shell)
eval `rbenv "sh-$command" "$#"`;;
*)
command rbenv "$command" "$#";;
esac
}': not a valid identifier

Thank you Yevgeniy Anfilofyev,
The solution was to use TinkerTools and delete my ~/.bash_profile
Then start over again

Related

bash_profile syntax error

I am getting a syntax error in my .bash_profile when I start up the terminal on Yosemite. Everything I have found online suggests there is nothing wrong with my syntax, although i am getting an error in line 4. Here is error, followed by the .bash_profile code. Can anyone see what is wrong? Is this affecting my ability to install rails (I seem to be having some difficulty with write permissions):
The error:
-bash: /Users/admin/.bash_profile: line 4: syntax error near unexpected token `fi'
-bash: /Users/admin/.bash_profile: line 4: `eval "$(rbenv init -)"; fi'
The .bash_profile code:
export PATH=/usr/loca/bin:$PATH
eval "$(rbenv init -)"
if which rbenv > /dev/null
eval "$(rbenv init -)"; fi
if which rbenv > /dev/null; then eval "$(rbenv init -)";
fi
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Thanks!
The if statement on line 3 does not have a matching then. Until bash sees a then, it doesn't let you use a fi.

RVM not reading .rvmrc files when I open a new tab in my terminal

rvmrc is getting called when I visit that folder using 'cd'. But when I'm opening it in new terminal using ctrl+shift+t, rvmrc is not getting loaded.
Here is some more detail:
tech#pc113:~/workspace/apps$ type rvm | head -1
rvm is a function
-bash: type: write error: Broken pipe
tech#pc113:~/workspace/apps$
echo $PATH
/home/tech/.rvm/gems/ruby-1.9.3-p551/bin:/home/tech/.rvm/gems/ruby-1.9.3-p551#global/bin:/home/tech/.rvm/rubies/ruby-1.9.3-p551/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/tech/.rvm/bin:/home/tech/.rvm/bin:/home/tech/.rvm/bin
echo $GEM_HOME
/home/tech/.rvm/gems/ruby-1.9.3-p551
echo $GEM_PATH
/home/tech/.rvm/gems/ruby-1.9.3-p551:/home/tech/.rvm/gems/ruby-1.9.3-p551#global
which rake
/home/tech/.rvm/rubies/ruby-1.9.3-p551/bin/rake
Any idea?

Error while installing ruby on rails on server

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.

.rvmrc syntax error

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

Installed RVM, rvm commands do not 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

Resources