Bash-profile error and Rails - ruby-on-rails

I tried to edit my bash_profile earlier. I think I put a space after the '=' and then I couldn't use any command line tools. I've now managed to get them back, although my terminal now says I don't have rails installed. I sudo install it, but it fails because it asks me to replace the rake gem with the rake executable. I say no to that request. I have been using rails to follow a tutorial. Unless it has been wiped, I have it. There must be something wrong with the path, but I don't know what the bash_profile should be. It is currently:
PATH=/usr/local/rvm/bin:$PATH
PATH=/Users/me/.rvm/gems/ruby-2.0.0-p247/bin
PATH=Users/me/.rvm/gems/ruby-1.9.3-p448/bin
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
"$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into $
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
I don't know how to go about fixing this.Thanks in advance for any help you might be able to offer.

These two lines replace the entire PATH with a single directory:
PATH=/Users/me/.rvm/gems/ruby-2.0.0-p247/bin
PATH=Users/me/.rvm/gems/ruby-1.9.3-p448/bin
There is now absolutely nothing in your command search path except "Users/me/.rvm/gems/ruby-1.9.3-p448/bin", with missing / so that it only works if you're in the root directory, no less.
Then you add some stuff to the PATH without replacing what's there, which is fine, but then you do this:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Which completely undoes all of that and gives you just the above literal path.
You generally don't want to assign to PATH without a $PATH somewhere on the right hand side.

Related

how do I change default editor for sudo vipw from "vi" to "vim" by tcsh in FreeBSD

When I use command sudo vipw to edit my password file, It's always use vi as editor. I don't like this very much and want to change it to vim.
I already tried:
Add export EDITOR=/usr/local/bin/vim in /etc/profile.
But shell told me "export: Command not found". I thought the reason is export is built-in function only in bash. And I don't want to change my shell.
AddEDITOR=/usr/lcoal/bin/vim in default block of /etc/login.conf
Add setenv EDITOR vim in /root/.cshrc, /.cshrc, ~/.cshrc
All above didn't work at all.
I have google for hours but could not find anything help.
Your /etc/sudoers file doesn't keep your EDITOR environment variable.
I personally have an /etc/sudoers.d/local file, something like
# We don't need to worry about wheel users breaking in to get root access because they already have it.
Defaults:%wheel env_keep+="HOME EDITOR",!set_home,shell_noargs
I'm not sure why this isn't the default, since wheel users have already been given full access. But it's apparently prevailing wisdom to continue hassling them.
Note: If you're using an older /etc/sudoers file that doesn't support an /etc/sudoers.d directory, these lines can be dropped in there... or you could add #includedir /etc/sudoers.d as the last line of your /etc/sudoers file to enable an /etc/sudoers.d directory. Um, yes, the # is a required part of that line, because someone thought it was important for that directive to look like a comment.
Try adding this to the root user /root/.chsrc:
setenv EDITOR vim
or to set it globally to all users using shell tcsh/csh add it in /etc/csh.cshrc
From the man:
A login shell begins by executing commands from the system files /etc/csh.cshrc
and /etc/csh.login. It then executes commands from files in the user's home directory:
first ~/.tcshrc or, if ~/.tcshrc is not found, ~/.cshrc ...
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on startup.
Also verify vim is installed since is not by default, you could try:
pkg install vim-console
setting the EDITOR or VISUAL environment variable is the key.
if you don't want to go to the trouble of modifying config files (which is indeed the long term solution) then you could sudo su - to get to the root prompt and then you could export EDITOR=/usr/bin/vim before running vipw
There is an empty file called .selected_editor in $HOME (/root).
Remove it and the next call to vipw will ask you to select the editor.

How to remove the existing environment variable in Linux?

This is my machine path :
~$ echo $PATH
/home/sam/.rvm/gems/ruby-2.1.2/bin:/home/sam/.rvm/gems/ruby-2.1.2#global/bin:/home/sam/.rvm/rubies/ruby-2.1.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/sams/.rvm/bin:/usr/local/bin
Here, I want to remove all the paths related to rvm
I removed all the above lines from .bashrc and .bash_profile but still it exists in the GEM_PATH where else it is erased from the common PATH
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
check:
echo $PATH
you can add the export code inside .bashrc
The first place to look for alternations in the $PATH variable would be your .bashrc file. Look for something like:
export PATH=/your/homefolder/.rvm:$PATH
Another thing worth asking, do you have this behaviour on startup of the system or is it just in one local shell window? If it's only in the current shell session (and not in the .bashrc or something similar), it will not stick/be permanent.
You can manually overwrite your PATH through exporting it again, but that only affects the current session.
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
If you want the change to last, you have to find where the rvm parts are added to the PATH variable. That's probably at the end of the ~/.bashrc (or ~/.profile, or ~/.bash_profile, or /etc/profile, .. it depends on how you installed rvm) file. You can safely remove those lines that add rvm to the path.
In case you also want to uninstall rvm (which I suspect if you go the second route), do a
rvm implode
To remove Rvm, run
$ rvm implode
Are you SURE you wish for rvm to implode?
This will recursively remove /Users/gaurish/.rvm and other rvm traces?
(anything other than 'yes' will cancel) > yes
Removing rvm-shipped binaries (rvm-prompt, rvm, rvm-sudo rvm-shell and rvm-auto-ruby)
Removing rvm wrappers in /Users/gaurish/.rvm/bin
Hai! Removing /Users/gaurish/.rvm
This will remove RVM & its entire from your path.
ANd if you want to keep rvm or have already removed it manually. Now, just want to get rid of the rvm related entries from PATH. find this line which is responsible for adding rvm to your path:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
using grep
$ grep -nr 'PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting' ~
Now, you will have the list of files along with line number that contain this line. you can ignore any entries in history. Mainly focus on entires in ~/.bashrc, ~/.profile, ~/.zshrc and other config files. And remove each of those

How to change back to the first_app directory?

I'm new to Ruby and am trying to make my way through the Hartl tutorial. I ran into a couple issues this morning and am afraid that I might have made one of them worse.
I was doing fine in the tutorial until I got to the Heroku deployment section of chapter 1 and realized that I had yet to setup the Sublime Text 2 "subl" command so that my terminal could interact with Sublime Text.
I then went on a chase to figure out how to get the subl command to work. While trying to get that figured out, I came across this thread (Installing Sublime Text's command line tool 'subl' in terminal, permission denied?) and went ahead and changed directories to the "mkdir bin" so that I could run "sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/bin/subl" and get my subl command line to work.
Well, when I entered the "sudo ln -s...." line it asked for a password and basically said I should be careful what I was doing. In light of that, I just want to return to my "first_app" directory and try to figure stuff out a different way. Only problem is, when I hit "cd first_app" it tells me there is no such file or directory... I'm starting to freak out a little bit now...
How can I get back to the first_app directory? Surely it's not gone?!' <-- most important!!
If I can get back to the first_app directory, how in the world can I get the subl command line so that I can continue on with deployment, etc...?
Any and all help is much appreciated as I try and work through this really frustrating phase.
UPDATE: I just changed it back to the first_app directory -- what is the best way to get this subl command line working?
Depending on what directory you're in, if you try to cd first_app, it may not be a sub-directory of the dir you're currently in.
Some basic linux commands to help you out:
cd .. <-- Moves up a level
pwd <-- Shows where you currently are in the directory structure
ls <-- Shows files/folders that exist in the directory you are in.

I'm clearly missing something... 'ruby' doesn't work but './ruby' does (centos 5.5, installed from source)

Trying to get a rails server running nicely.
downloaded ruby 1.8.7 using link from rails page.
did ./configure/make/install, installed it fine.
tried ruby -v , got nothing.
tried ./ruby -v from the folder and it worked.
I feel like i've gone from understanding something about unix, to completely lost. Clearly ruby is working as a 'daemon', but not running as it should. Any help would be MUCH appreciated. Losing too much hair through this process :(
J.
can you see where make install put the ruby executeable?
if you do, check if this dir is in your $PATH by
echo $PATH
In general, unix needs to know where to find the executable file to be able to run it. It uses $PATH to find this executable file.
So if you type "ruby" it will go look at you $PATH and then look in each of those directories for a file named "ruby". If it can't find it in any of those directories it should then also look in the current directory.
So, this whole process will fail if:
a) the directory that contains the executable ruby file is not in any of the directories in $PATH AND
b) the executable is not in the current directory
... one more alternative is that is is available in one of these directories... but is not actually marked as being executable by you. You can check this by making sure you're int e directory with the ruby file and typing "ls -l ./ruby"
That will list the ruby file along with all its permissions and who owns it.
It should be something like:
lrwxrwxrwx 1 root root 7 2010-02-14 10:45 ./ruby
Notice the rwx. If your ruby doesn't have x then you'll need to add executable permission using chmod eg: "chmod 755 ./ruby"
Also note the "root root" - that means it's owned by root - in general, this means that only root can run it. In this particular example it has eXecute permission for everyone so everybody can run it, but if you do not have execute permission set like this, then it means that if you are trying to run it as yourself, you won't have permission, and you should either add full permissions or try running it using: "sudo ruby"
However - by the sounds of it - the most likely problem is that you just don't have the ruby executable's directory in your $PATH. You will need to fix this even if you get it running right now - because, in future, you will need to run ruby from directories other than the current one.
You will need to google for instructions on adding things to your $PATH - because it differs depending on your version of linux and your current shell, but it's not very difficult.
Which shell are you running? If tcsh, you may need a "rehash". Otherwise, as leifg says, add the directory containing the ruby executable to your path.

RVM not found, after installing RVM

I've found a couple similar posts regarding this same problem, but none of the solutions seem to apply, here.
On a fresh Ubuntu 10.10 install, I follow the instructions for installing RVM:
$ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Then I create .bash_profile and add the following line:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
I restart the terminal and check RVM:
$ type rvm | head -1
-bash: type: rvm: not found
As the RVM installation guide explains to do so, I replaced the first line (below) in .bashrc with the second one, then indented everything in the rest of the file and added a fi.
[ -z "$PS1" ] && return # original
if [[ -n "$PS1" ]]; then # replaced with this
Restarted terminal and still, no luck.
Then, I removed the line I added to .bash_profile in the beginning and added it to .bashrc, even though that isn't what the guide said to do. Still, no luck. I also entered it directly on the command line, with no change in behavior. When I run .rvm from ~/.rvm/bin/rvm it complains that there is no such file or directory as /.rvm/scripts/rvm and that the command was not fund.
Of course, there isn't any such "scripts" directory inside of ./rvm, either -- so I'm not sure why it's looking for one? The only directories inside of .rvm are
archives
bin
config
gems
gemsets
log
man
rubies
src
tmp
user
The only thing I've found while googling for answers are other people complaining of similar problems and people telling them to add the instructed line to .bash_profile (which I obviously already did). At this point, I have nothing more to go on and am at an impasse.
Regards.
Resolution:
As Andrew Marshall advised in his comments, below, I did an 'rm -rf .rvm' and reinstalled rvm. I had actually attempted this two times before posting here, with the same results every time. No odd messages in the install log, but no /scripts/ directory, either. Just so I could say I had, I did it a third time at Andrew's urging. This time, I checked and the /scripts/ directory existed. Running 'type rvm | head -1' confirmed it as a 'function' and I can now move on.
Make sure that you restart a session after reinstalling, so that rvm is in your path.
You can try to logout/login.
You can also open your shell as a login shell. Under ubuntu 12.04:
Open a terminal
Edit > Profile Preferences
Under tab Title and Command, check run Command as a login shell
Open new terminal (ctrl+alt+t) and type rvm
If there's no scripts directory inside .rvm, it would seem that RVM failed to successfully complete installation. Delete the .rvm directory, try reinstalling, and look at the installation output closely to see if it's complaining about anything.

Resources