I'm going through the rails by example tutorial series. I'm trying my best to find solutions prior to asking questions, so if I have missed anything I apologise.
Every time I need to boot up RVM from the command line in terminal I need to punch a command so that RVM initialises: source ~/.rvm/scripts/rvm
Is this normal? It seems that I cant get the RVM commands to work unless I punch in this code prior. Note I only have to enter the command once, not every time I need to enter an RVM command.
Many thanks for your help.
Put this in your ~/.profile or ~/.bashrc:
# This loads RVM into a shell session.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"
So you don't have to manually type it for every session.
Further Tip
If you want to use gnome terminal (comes as standard in Ubuntu) with rvm, you can do the following:
Edit the default profile. Check the following setting:
"Run command as a login shell"
This will stop loading the standard .bashrc by default. Fix this by making a soft link of .rvmrc pointing at .bashrc in your home directory
cd
ln -s .bashrc .rvmrc
Try closing terminal and then re-opening it to install a specific version of Ruby as seen in this video at 2:32.
For example, I typed curl -L https://get.rvm.io | bash -s stable --ruby
Then I quit and reopened the terminal, typed rvm install 2.2.3 and it worked.
If your rvm command is not found:
(to check, enter the command rvm list, which gives:)
/bin/bash: rvm: command not found
To solve it, follow these steps:
Install rvm
whereis rvm
rvm: /home/username/.rvm/bin/rvm
source ~/.rvm/bin/rvm
now test your rvm again
rvm list
Related
My system was fine, but today, after installing MySQL server, I can't use the terminal to program my Rails application.
When I open a terminal session, I see:
Last login: Sun Dec 8 13:31:06 on console
-bash: [: missing `]'
-bash: rt: command not found
I tried searching for this error but can't find a solution.
I am running Mac 10.7 OS X.
No commands pertaining to Ruby on Rails are found.
I built an application and installed Rails, but when I run a Rails command I get:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
You can then rerun your "rails" command.
How do I fix this?
My bashrc file contains only one line:
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
My bash profile contains following:
export PATH=$PATH:/usr/local/mysql/bin
[ [-s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
rt PATH=$PATH:/usr/local/mysql/bin
I checked history and this is what I ran
vi .bash_profile
vi .bash_profile
user#computer:$ mysql -u root
mysql -u root
vi .bash_profile
mysql -u root
/usr/local/mysql-5.6.15-osx10.7-x86_64/bin/mysqld_safe ; exit;
mysql
What else can I show to help with this problem?
Your .bash_profile is messed up. Modify what looks like this:
[ [-s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
rt PATH=$PATH:/usr/local/mysql/bin
To look like this:
[[-s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH=$PATH:/usr/local/mysql/bin
As #TinMan pointed out, you'll want to remove the export PATH line from your .bashrc file.
I had a similar problem (although I'm running Ubuntu). When I opened a new terminal and navigated to my project root, I was surprised to find that Rails was not recognized as a program. I checked the version of Ruby and noted that there was a discrepancy between the two terminals I had open. When I tried to switch Ruby versions with RVM, I was told
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
so I ran /bin/bash --login. Then, I was able to switch to Ruby 2.1.1 with RVM use ruby-2.1.1 and all my rails commands worked again.
Basically what happened is that RVM only installs gems locally for each Ruby verison. Unless you select the version of Ruby that you were using when you installed the gem, you won't be able to use the gem unless you reinstall it.
I came to this page after receiving this error with a slightly different cause. While the CDub's answer is directly applicable to OP's question, I would generally recommend users of Mac OS X Terminal who have this error to do the following:
Open ~/.bash_profile in a text editor.
Look for any instances of "rt" at the beginning of a line.
Change all instances to "export".
It looks like some packages out there are writing a command into ~/.bash_profile that Mac OS X does not like, and we need to manually correct this.
For reference, I am on OS 10.10.2.
I installed rvm with rails, from the official website of RVM, I specified the command suggested by the tutorial.
When the installation my system has rails 4.0.0, rvm 01/23/12, ruby 2.0.0, bundler gem 1.3.5 and 2.0.3
But I need to install ruby 1.9 to practice with a course that I am currently doing. "Rails for Zombies 2"
I try to execute the instruction rvm install 1.9.3 and the console returns this message:
rvm: command not found
Possible duplicate of: Ubuntu rvm setup issue
Your problem is that RVM is not loaded when you open a new terminal.
To solve this, run this command line: (if using login-shell)
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
Or this (if using non-login shell):
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bashrc
Or if you are using zsh (and/or oh-my-zsh):
echo "source $HOME/.rvm/scripts/rvm" >> ~/.zshrc
This will add the path to RVM to load at each Terminal instantiation. You must either close and reopen your terminals or simply call source ~/.bashrc (or ~/.bash_profile or ~/.zshrc).
I had this problem after installing zsh. I'm a domain user so my $PATH and $HOME are not as straight-forward. What worked for me was
echo "source /usr/share/rvm/scripts/rvm" >> ~/.zshrc
The latest installation needs the users to be added to the Group rvm and then need to login again.
Please note that closing the terminal and reopening is not enough; the user has to logout and log back to take the Group addition in effect.
Adding the user to the Group can be done by:
sudo usermod -a -G rvm <user>
The binaries can also be at different locations based on the method you followed during the installation.
I had them at /usr/share/rvm/
You can also look at /usr/local/rvm/scripts/rvm
Then you add this line to the end of ~/.bashrc
[[ -s /usr/share/rvm/scripts/rvm ]] && source /usr/share/rvm/scripts/rvm
Note: If you are using a shell other than bash you may need to add the path accordingly.
For instance, if you using zsh shell add the above lines to the ~/.zshrc file.
I know the above question is very common question. I have gone through multiple posts on this topic. But I didn't get any resolution.
I have installed rvm locally. We already have the installation files. SO went into the folder and run the install command.
$ ./install
Then I checked ./rvm folder in the Users home folde
$ cd ~/.rvm
folder exists. Hence Installation is successful.
Now I am typing rvm in the command line
$ rvm
I am getting below exception
$ rvm
-sh: rvm: command not found
After reading the multiple articles in stackoverflow on this issue, I learned that I have to add the below lines in .bash_profile as I am using Mac OSX 10.7.3
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
Even after I am getting same exception while typing rvm. Is there any thing extra I need to do? or Am I missing some thing? Please help
Steps to try out:
Log out and login to your system.
Open a new terminal and manually run
source $HOME/.rvm/scripts/rvm
then
rvm
Check these work-arounds.
Update:
To avoid running
source $HOME/.rvm/scripts/rvm
every time you open a terminal, include this line into ~/.MacOSX/environment in your Mac (This is similar to ~/.bashrc in GNU/Linux-based systems under $home aka ~ directory).
In my case, i am using Ubuntu Bash in Windows 10 and to fix the problem i used:
source /usr/local/rvm/scripts/rvm
For those that are doing this in 2018 just
add
source $HOME/.rvm/scripts/rvm
to your .bash_profile within your home directory.
you need to enable login shell in terminal emulator preferences, sometimes it is needed to use /usr/bin/bash --login, here is an example https://rvm.io/integration/gnome-terminal/
after enabling login shell you need to close terminal application and open it fresh.
I just had to open a new Terminal session.
After I installed it using:
curl -sSL https://get.rvm.io | bash -s stable --ruby
rvm install 2.2
For Ubuntu 18.04, I had to run the command below to solve the issue after rvm was installed using instruction from here.
source /usr/share/rvm/scripts/rvm
This is one of other options available for RVM:
source /etc/profile.d/rvm.sh
In chapter 1.2.2 of Michael Hartl's Ruby on Rails tutorial we are using rvm to install rails.
Following the first few steps is no problem.
But when I get to this command:
rvm use 1.9.3#rails3tutorial2ndEd --create --default
I get this response.
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
I did a lot of research before posting this question. But could not find one that addresses my problem specifically.
I'm using linux under Ubuntu (in a VM on Windows 7).
Thank you.
The above is one way to fix it, although RVM says you should instead change your shell settings.
Press ctrl+alt+t to bring up the terminal, and then go to edit >> profile preferences >> title & command tab, then select "Run Command as Login Shell".
That should work as well.
You have probably not yet installed RVM correctly.
Make sure that you source RVM from your .bash_profile or .bashrc file.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
This is what I have in my .bash_profile for RVM to work. (After adding this restart your console or type source ~/.bash_profile
I have installed ruby via rvm on Mint 11 no problem. Installed gems, ditto. Installed rails via gem install rails, and when I type rails -v it returns the correct version. Until I close that terminal and reopen a terminal. When I do that and type rails -v I get the message
The program 'rails' is currently not installed. You can install it by typing: sudo apt-get install rails
If I then type
rvm use 1.9.2-p180 --default
and then type rails -v I again get the correct version...until I close the terminal.
I should add that I have added a path statement to my .bashrc pointing to the 1.9.2-p180 directory in my .rvm directory.
Typing ruby -v always returns the correct version.
Create .bashrc file and add .rvm command
$ sudo touch ~/.bashrc
$ sudo gedit ~/.bashrc
(Add line to .bashrc file)
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then source "$HOME/.rvm/scripts/rvm" ; fi
Logout and Login OR just update user profile from .bashrc with following command
$ . ~/.bashrc
Try adding this command to your .profile and reopening your shell:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Use project rvmrc files. You can see how to set this up here http://beginrescueend.com/rvm/best-practices/
That way you keep all your gems seperate for each project and it's dead simple to set up
Try which rails. Maybe there is a link to a stub that gives you the note.
If that is the case calling the full path might help, e.g. /usr/local/bin/rails