ruby in linux: permanently "source .rvm/scripts/rvm"? - ruby-on-rails

I'm new to Ruby on Rails and have just set it up in Ubuntu Linux following instructions I found here. Specifically,
As s.m. said, I uninstalled everything, then I opened another terminal session as a normal user and run:
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
then i run source /home/my-desktop-username/.rvm/scripts/rvm as a normal user NOT ROOT
then i run rvm requirements as a normal user. Then I copy the requirements and close the session, open a root session and install the requirements using sudo
Then I close the session and open a normal user session and run rvm install ruby-1.9.3-p125 if you run this command as root, it will say that rvm is not installed and will suggest that you install it using sudo apt-get install rvm Don't do that!
So basically I had two problems, the tutorials that i followed didn't say that i should run
source /home/my-desktop-username/.rvm/scripts/rvm and didn't say that I should not run rvm as root, s.m told me that. Thanks to everyone, especially to s.m
That works well, but I will have to remember to
source .rvm/scripts/rvm
every time I open a terminal to work with Ruby on Rails.
Is there a way to permanently tell Ubuntu to look in .rvm for all the Ruby stuff?

You need to add your
source .rvm/scripts/rvm
into your $HOME/.bashrc file; read the advanced bash scripting guide for more.

Related

Rvm ruby Permission denied

I have installed rvm for multiuser,
when I am doing bundle install, it is giving me error,
linux:/var/rails_apps$ bundle install
ERROR: RVM Ruby not used, run `rvm use ruby` first.
linux:/var/rails_apps$ rvm use ruby
mkdir: cannot create directory `/usr/local/rvm/log/ruby-2.0.0-p247': Permission denied
I already did,
sudo chmod 777 /var/rails_apps/
Please suggest..
You have a multiuser installation of rvm - this is not recommended because of the troubles you can get with it (like yours).
Since you are already there this should fix it:
rvmsudo rvm get stable --auto-dotfiles
rvm fix-permissions system
Also make sure you are in rvm group - if not add yourself:
rvm group add rvm $USER
and log in to a new shell (log out and log back in).
In most of the cases rvm fix-permissions will resolve the problem for single user access but it fails in some cases while making other rvm commands thereafter. So do it with rvmsudo after the fix-permissions command consecutively as
rvm fix-permissions
rvmsudo rvm use ruby
For those who may have issues after running the commands shared on every thread out there, try opening ubuntu or the Linux environment you are working with as an administrator.
1 - Search for your app (in my case Ubuntu) using the search bar on the bottom-left of your computer's screen.
2 - if you don't see the option "open as administrator" on the right side, then right-click over the app's icon and you should see it then.
3 - Allow the app to make changes on your computer when prompted and then try the installation commands again.
4 - If that didn't work then try the commands shared in this or other posts, but always as administrator.

I am getting rvm: command not found after installation of rvm

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

Install RVM itself without internet connection

I am switching from DJANGO to Rails, but i don't know how to install RVM in PROD environment.
My PROD server is without internet connection, and not possible connect even for a while. And i cannot find a standalone install package of RVM.
Is there any solution for offline RVM installation?
BTW, can rails be installed without internet?
I just spent some time and build a tutorial for the offline mode: https://rvm.io/rvm/offline - it's the first version so feel free to improve it here: https://github.com/wayneeseguin/rvm-site/blob/master/content/rvm/offline.md (Edit button).
Additionally to my first answer another way to do it would be to compile ruby on online machine, then package it, unpack on the other end and add it to PATH on the offline machine.
Way 1 - only Ruby
curl -L https://get.rvm.io | bash -s stable
source $HOME/.rvm/scripts/rvm
rvm install 1.9.3 --movable
rvm prepare 1.9.3
Some information will be displayed, including file name. Copy it to the offline machine and unpack it there, then just add it to PATH:
echo 'PATH=$PATH:${unpacked_dir}/bin' >> ~/.bashrc
Way 2 - whole RVM:
curl -L https://get.rvm.io | sudo bash -s stable
source /usr/local/rvm/scripts/rvm
rvm use 1.9.3 --install
gem install rails -v 3.2.8
rails new rails3
rvm use 1.8.7 --install
gem install rails -v 2.3.14
rails new rails2
tar czf rvm_and_ruby.tgz /usr/local/rvm /etc/rvmrc /profile.d/rvm.sh
Unpack on the offline end:
cd /
sudo tar xzf rvm_and_ruby.tgz
And open a new terminal.
check http://railsinstaller.org/ (for windows and mac) .After then change environment into production mode . In linux this works export RAILS_ENV=production .
If you are using a linux OS, you can always package the app as a debian or rpm archive which will include rails and the dependent gems referred in your Gemfile. The advantage with this approach is that you can also configure the archive to setup external dependencies like any other deb or rpm package. One of my recent projects came up with a in house solution. Now there are tools like pkgr
You can download a standalone RVM package here: https://github.com/wayneeseguin/rvm/tags
You can reference the RVM installer script for details on what an RVM install does. Simply replace the network calls with references to some local file, and you should be good to go.
That said, once RVM is installed, I'm not sure if it'll let you do an offline Ruby install easily, but this should get you started.
Well you need to download the source code from somewhere to install RVM, Rails. Not very clear as to how your Prod environment lacks an internet connection. Could you please give more details?

Cannot install RVM . Permission denied in /usr/local/rvm

Based on my previous thread : RVM installed by Ruby not working? where i had installed RVM using the root user, I then had to entirely remove the RVM install and now i am installing as a user.
So i did :
Create a new user by doing : useradd newuser
Follow the instructions on the RVM website and execute the command : bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Now, i get the error : mkdir: cannot create directory `/usr/local/rvm': Permission denied
The new user i created does not have access to this directory. I manually tried creating the folder but the same error. Please help.
EDIT : The original problem occured because i did not restart the terminal and it was still using the old settings.
Now, I got a new problem : After installing RVM, i cannot run it and it gives me an error : rvm command not found.
Here is the output of my ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
And here is output from ~/.bashrc file
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
mkdir: cannot create directory `/usr/local/rvm': Permission denied
If you've run the rvm installer as root previously, remove /usr/local/rvm and /etc/rvmrc.
RVM is easy to install, but you are making it harder by trying to mix and match installation types. You do NOT need to create a new user. When run, RVM will create a directory in your home directory: ~/.rvm, and install everything inside it. That means you will have all the correct permissions. You do NOT need to be running as root, you do NOT need to use sudo. I'd recommend closing all your command-lines and open one fresh and start at your home directory. If you are running as root, log out, and log back in to your normal account. For a single-user install you do NOT need to be root.
For a single user, using RVM as their Ruby sandbox, use the single-user installation docs. Follow ALL the instructions on that page, INCLUDING the "Post Install" section.
Close your terminal window, and reopen it. If you have correctly followed the instructions above, typing rvm info should spit out a template of what is to come once you install a Ruby instance. If you see nothing output, or get an error, then retrace your steps in the "Post Install" section, and go through the "Troubleshooting" section. Most of the problems people have occur because they didn't bother to read the directions.
Once RVM is installed, type rvm notes and read what dependencies you need to install. If you do not add those files your Rubies installed will be missing functionality. They will work, but some of the creature comforts you'll hear about won't work and you will wonder why.
After installing the dependencies you should be in good shape to install Rubies. Type rvm list known for all the Rubies RVM can install. If you want 1.8.7 type rvm install 1.8.7, and, similarly, rvm install 1.9.2 for Ruby 1.9.2. If you want a particular revision you can add that, based on the ones in the list.
It's important to periodically update RVM using rvm get head. That will add features, fix bugs, and tell RVM about new versions of Ruby it can install if you request.
After installing a Ruby, type rvm list and it should show up in the list, looking something like this:
rvm rubies
ruby-1.8.7-p334 [ x86_64 ]
ruby-1.9.2-p180 [ x86_64 ]
Type rvm use 1.9.2 --default to set a default Ruby that will be sticky between logins. Use the version of whatever Ruby you want to default to if 1.9.2 doesn't float your boat. Once you've defined a default it should look something like:
rvm rubies
ruby-1.8.7-p334 [ x86_64 ]
=> ruby-1.9.2-p180 [ x86_64 ]
Before you begin installing gems into a RVM-managed Ruby, read "RVM and RubyGems ", in particular the part that says "DO NOT use sudo... ". I repeat. Do NOT use sudo to install any gems, in spite of what some blog or web page says. RVM's author knows better when it comes to working with RVM controlled Rubies. That is another mistake people use with RVM, again as a result of not reading the directions.
On Mac OS, you'll need the latest version of XCode for your OS. Do NOT use the XCode that came with Snow Leopard on the DVD. It is buggy. Download and install a new version from Apple's Developer site. It's a free download requiring a free registration. It's a big file, approximately 8GB, so you'll want to start it and walk away. Install XCode, and you should be ready to have RVM install Rubies.
Finally, RVM installs easily, as will the Rubies you ask it to install. I have it on about four or five different machines and VMs on Mac OS, Ubuntu and CentOS. It takes me about a minute to install it and another minute to configure it and start installing a new Ruby. It really is that easy.
I had the original issue reported in this question, "mkdir: cannot create directory `/usr/local/rvm': Permission denied" when trying to install rvm.
This is my scenario and how I solved it - maybe this will help others with this same issue.
I have Ubuntu 11.04 installed on a laptop, I only have 1 user, the one I created at install time, named nathan. When I would try to install rvm as nathan, the rvm installer saw me as root and kept trying to install rvm globally, but since I wasn't really root, it couldn't get access to create directories in /usr/local/rvm.
I'm far from an expert with Ubuntu, so I'm sure there are easier/better ways to accomplish the things I did (and I would love to learn about them), but this worked for me:
I created a new user called rubydev
I logged in as rubydev, opened a terminal and typed:
rubydev~$ bash < <(curl -B http://rvm.beginrescueend.com/install/rvm)
rvm installed correctly and I logged out of rubydev
Signed back in as nathan, opened a terminal and typed "su" (you could do all this with sudo, I am lazy)
After successfully getting root, I typed the following commands:
root: /home/nathan# cp -R /home/rubydev/.rvm .
root: /home/nathan# chown -R nathan .rvm
root: /home/nathan# chgrp -R nathan .rvm
root: /home/nathan# exit
nathan~$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
nathan~$ echo 'export rvm_path="/home/nathan/.rvm"' > ~/.rvmrc
nathan~$ source .bash_profile
At this point, rvm was correctly installed under my home directory. To verify I typed:
nathan~$ type rvm | head -1
rvm is a function (if you don't get this response, something else is wrong)
Read the notes and installed any dependencies
nathan~$ rvm notes
I installed some rubies
nathan~$ rvm install 1.8.7-head
nathan~$ rvm install 1.9.2-head
Verified install
nathan~$ rvm list
rvm rubies
ruby-1.8.7-head [x86_64]
ruby-1.9.2-head [x86_64]
nathan~$ rvm use 1.9.2
using /home/nathan/.rvm/gems/ruby-1.9.2-head
nathan~$ rvm list
rvm rubies
ruby-1.8.7-head [x86_x64]
=> ruby-1.9.2-head [x86_x64]
Finally, I edited the preferences on the terminal itself to ensure the "Run command as as login shell" under the "Title and Command" tab was checked. It seems .bash_profile isn't otherwise processed.
I removed the rubydev user I created in step 1.
With all of that, I have a working rvm under Ubuntu 11.04 using my preferred username.
I solved this by adding
export rvm_path=~/.rvm
to ~/.bash_profile
If you first installed RVM as root and then uninstalled it. And now you are trying to install it as a non sudo user and you're getting the following error:
mkdir: cannot create directory `/usr/local/rvm': Permission denied
Make sure that you have logged out of the root session before trying to install under the user.
If you installing RVM as a user then the RVM folder should be generated in your home directory:
~/.rvm
Where there should be no permissions problems at all.
I would suggest it is picking up some old config that is left over from your system installation.
Ensure there is no /etc/rvmrc or $HOME/.rvmrc file left over because it might be using previously initialised variables from these files to construct an incorrect installation path.
if we look at this section of the bash script:
if [[ ${rvm_ignore_rvmrc:-0} -eq 0 ]]; then
for file in /etc/rvmrc "$HOME/.rvmrc " ; do
if [[ -s "$file" ]] ; then
source $file
fi
done
fi
It is trying to find one of these files, if it finds one if will run it possibly initialising rvm_path which will subsequently not be set as $HOME/.rvm by this command
rvm_path="${rvm_path:-"$HOME/.rvm"}"
I had the same issue. When I tried to create a gemset I would get a permission denied error. I just forgot to run the "rvm use 1.8.7" command first. After that I was able to create and use the gemset without any problems.
In lasts versions of rvm you need remove /etc/profile.d/ also.
This happen often if you try to install as root and then try again as a regular user.
Hope this help.
Look for file rvm.sh below /etc directory (It may be in /etc, or /etc/init.d).
Also, try some grep rvm /etc -r, so you can find some files/lines which prevent you from installing rvm in your $HOME dir.
For me running
__rvm_unload
Worked first, this was due to the fact that I had rvm installed as for multiuser.
If you installed rvm as root and you are getting permission denied issues (maybe you are deploying with capistrano as a non root user) then you could try rvm fix-permissions after doing things like rvm install 2.2.2 as root and creating a gemset as root.
Scott Bartell's solution worked for me. i am on a Digital Ocean premade image, where they had already setup rvm as root.
1. deleted /etc/rvmrc .
2. added export rvm_path=~/.rvm to ~/.bash_profile
3. logged out of ssh session to virtual machine
4. logged back in and presto!
would have commented but rep is 3 points too low :)

How to run a command automatically after each reboot

I currently have Ubuntu 16.04 installed on my virtual box. I installed Ruby and Rails by RVM. After that I tried
$ rails
The terminal said
The program `rails` is currently not installed. You can install it by typing:
sudo apt install ruby-railties
I solve this problem by typing
$ source ~/.rvm/scripts/rvm
Credits here
However, once I reboot the virtual machine, everything I did with source will lose and I need to re-enter
$ source ~/.rvm/scripts/rvm
I also have some similar cases I need to do on every reboot.
So is there any solution can make those command be run automatically each time?
If you're using bash, add the line to the end your .bashrc:
.bashrc
source ~/.rvm/scripts/rvm
If you're using zsh, add it to you .zshrc.
Depending of which implementation of cron you're using it's possible to run jobs only after reboots, for example:
#reboot source ~/.rvm/scripts/rvm
Again. before editing your crontab make sure your cron implementation supports #reboot flag.
Another option is to include all your scripts in /etc/rc.local

Resources