I was following this tutorial (http://railsapps.github.io/installrubyonrails-ubuntu.html) of installing ruby with RVM on Xubuntu 14.04 running on virtual box. I completed this step with success:
$ \curl -L https://get.rvm.io | bash -s stable --ruby
However afterward I tried to run gem -v and got this output:
The program 'gem' can be found in the following packages:
ruby
rubygems
Try: sudo apt-get install
I also tried to reinstall Ruby with the argument --autolibs=enable but it did not change the outcome.
EDIT:
Running rvm list output:
rvm rubies
=* ruby-2.1.5 [ x86_64 ]
# => - current
# =* - current && default
# * - default
In your ~/.bashrc file paste this line at the bottom:
source "$HOME/.rvm/scripts/rvm"
Then restart your terminal session, and you should be able to gem install via RVM.
Look at your ~/.bash_profile file.
If you see a line like:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
then you just need to restart the machine (or log out and log in back).
Otherwise follow the Tin Man's instructions above, log out and log in again (or restart the machine).
Related
I've just setup an ubuntu server and need to deploy a small rails app. I'm using mina.
When I execute "mina setup", the following part of the code gives me a message(you can find it below the code) But the setup process finishes successfully.
deploy.rb
task :environment do
invoke :'rvm:use[ruby-2.2.2#default]'
end
-
$ rvm use "ruby-2.2.2#default" --create
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.
How can I get rid of this message?
I found a few similar topics but it didn't solve my problem.
here's how I installed rvm:
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ curl -sSL https://get.rvm.io | sudo bash -s stable
$ sudo usermod -a -G rvm `whoami`
ps
For the setup process I used info from the following articles:
Passenger library
Setting Up Ruby on Rails On Digital Ocean
I noticed that deploy.rb from second article has .bash_profile. I dont have this file( only .profile)
task :environment do
queue 'source ~/.bash_profile'
# For those using RVM, use this to load an RVM version#gemset.
invoke :'rvm:use[ruby-2.1.4]'
end
This is most probabaly because rvm is still not loaded to your bash. Load it using:
source ~/.rvm/scripts/rvm
followed by:
rvm use "ruby-2.2.2#default" --create
A permanent fix would be to add following line in your ~/.bashrc :
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
I am trying to set versiĆ³n ruby version in the vagrant user with rvm using the following script into the vagrant file:
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get -y update
sudo apt-get -y install git ruby libgdbm-dev libncurses5-dev automake libtool bison libffi-dev
nodejs
#Install ruby environment
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -L https://get.rvm.io | bash -s stable
sudo "source ~/.rvm/scripts/rvm"
echo "source ~/.rvm/scripts/rvm" >> ~/.bashrc
sudo /usr/local/rvm/bin/rvm install 2.1.5
rvm 2.1.5 --default
sudo chown -R vagrant:vagrant /usr/local/rvm/gems/
gem install middleman
git clone XXXX
SHELL
END
Vagrant is returning me the following message:
/tmp/vagrant-shell: line 10: rvm: command not found
But if i run the command with the full path it returns me the following message:
/usr/local/rvm/bin/rvm 2.1.5 --default
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for an example.
Is there anyway to execute the inline script in logging mode or other way to use rvm to set the default version?
Thanks :)
The alterations to the script provided would prevent the code above from exiting with an bad exit status.
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.provision "shell", inline: <<-SHELL
RUBY_VERSION="2.1.5"
sudo apt-get -y update
sudo apt-get -y install git nodejs
# Install ruby environment
if ! type rvm >/dev/null 2>&1; then
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -L https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
fi
if ! rvm list rubies ruby | grep ruby-${RUBY_VERSION}; then
rvm install ${RUBY_VERSION}
fi
rvm --default use ${RUBY_VERSION}
rvm all do gem install middleman
git clone <REPLACE_WITH_YOUR_REPO>
SHELL
end
Explanation of changes:
There is no need to source "~/.rvm/scripts/rvm". Firstly, it fails because it doesn't exist as mentioned previously due to vagrant running as a non-login shell. Secondly the installation of rvm creates startup files in /etc/profile.d/rvm.sh which handles this case for you. See https://rvm.io/integration/gnome-terminal. You will still see a warning (in red) in the vagrant's console output but the script doesn't fail because of a bad exit status. As a result we need to source /etc/profile.d/rvm.sh immediately after installing RVM because our current shell hasn't loaded rvm.sh yet. This was mentioned in the RVM installation output. An alternative is to break up the script into multiple parts to force trailing scripts to pick up the new path.
As vagrant is running as a non-login shell there is no need to change ownership of the /usr/local/rvm/gems/ folder. I think at some point vagrant did run scripts as the vagrant user but this has changed in more recent versions. Scripts will actually run as root; this occurs by default due to the privileged option on shell scripts; see Shell Provisioner. If you are uncertain which user is running you can do a whoami in the script. The script will run as the vagrant user if you de-escalate the privileges by setting privileged => false.
Added a conditional block around the rvm GPG key and installation. Unless you need rvm installed on every provision. An argument could be made that you might be trying to keep it up-to-date but that could potentially introduce unknowns and break the repeatable results from one day to the next.
Added a conditional block around the installation of the ruby version. This prevents the warning regarding the package is already installed, use reinstall.
Cleaned up the packages you were installing. You might re-look at this but the packages you were installing with apt-get will be automagically installed by the rvm installer and add extra fluff to your scripts.
Alternative and bit more flexible method
If you aren't stuck on using inline scripts. I would go the route as described in Using RVM with Vagrant. Some of the suggestions I made above I would re-apply to the general logical of the scripts in this article. One change that would be REQUIRED is in the install-rvm.sh script. Add the GPG key import; shown below:
#!/usr/bin/env bash
curl -sSL https://rvm.io/mpapis.asc | gpg --import -
curl -sSL https://get.rvm.io | bash -s $1
Question is very simple:
I cannot install RVM (single-user installation), as if I follow the instructions on the RVM website, that is:
$ curl -L https://get.rvm.io | bash -s stable
I get a permission denied error at line 360 of the installation script file (the line that starts with echo):
# Perform the actual installation, first we obtain the source using whichever
# means was specified, if any. Defaults to head.
case "${version}" in
(head)
echo "${branch}" > "$rvm_path/RELEASE"
install_head ${branch:-master} || exit $?
;;
Here is the error message:
olivier#~$ curl -L https://get.rvm.io | bash -s stable
bash: line 360: /usr/local/rvm/RELEASE: Permission denied
If I add "sudo" before "bash" in the command above, it works fine, but it is then the multi-user install ...
Indeed, I solved this by uninstalling old versions of RVM: sudo rvm implode and then deleting the file /etc/rvmrc. Once done, I could install the single-user version and everything worked fine!
Sorry Remear, I wanted to edit your answer or complete it via my comment but I could not (comment can only be edited within 5 minutes...at least I upvoted...).
Once you have a system-wide install, you can't run a single-user install as it will detect your system-wide install first and try to update it.
But it is possible to have a root install & then user install by specifying the installation path :
curl -sSL https://get.rvm.io | bash -s stable --path $HOME/.rvm
You will also have to set the single-user install path in your user path manually as RVM does not create it when you already have a system-wide install (not really an intended use) :
# .bashrc
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
And also load your user rvm :
# .bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Are you setting rvm_path in ~/.rvmrc, or in /etc/rvmrc, or in one of your bash scripts? I'd recommend removing both of those files as well as ~/.rvm and then try installing rvm again WITHOUT sudo.
this work for me, first uninstall all versions and then as user (NO root) follow the next commands:
For example, I'm using Ruby 2.6.3 and Rails 5.2.2 and setting up helping a little in these web pages:
https://gorails.com/setup/ubuntu/20.04
https://rvm.io/rvm/install
$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
$ curl -sSL https://get.rvm.io | bash -s stable --ignore-dotfiles
$ source ~/.rvm/scripts/rvm
$ rvm install 2.6.3
$ rvm use 2.6.3 --default
$ ruby -v
$ gem install rails -v 5.2.2
$ rails -v
Check the paths:
$ which -a gem
$ which -a ruby
Now you can Add some gems (inside you app directory):
$ gem install faker
All works great for me, hope this helps!
I am planning to create an installer for a ruby script but I want to be able to ensure that the machine has RVM installed. Is there a way to install RVM completely offline and unobtrusive as well(by unobtrusive, as in create a script that can do everything instead of ask users to add something to their bash_profile or bashrc)
I am not asking for the script itself, just a quick pointer as to how to go about this route(if it is even possible). We have also looked into this question which was helpful enough:
RVM - is there a way for simple offline install?
but a bit misleading as the answer only shows us how to install a ruby in RVM offline. We need to be able to install RVM itself offline, and looking at the script
https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer
do I just include this whole script and change the rvm_releases_url into something else? And is it safe to just append the rvm path to a user's bash_profile, or bashrc instead of asking them to do it?
As per the suggestion given editing this comment. :-)
Installing RVM offline :
- Download the rvm tarball:
curl -sSL https://github.com/rvm/rvm/tarball/stable -o rvm-stable.tar.gz
- Create and enter rvm directory:
mkdir rvm && cd rvm
- Unpack the tar file :
tar --strip-components=1 -xzf ../rvm-stable.tar.gz
- Install rvm:
./install --auto-dotfiles
use --help to get the options
- Load rvm:
source ~/.rvm/scripts/rvm
Download Ruby, rubygems and yaml :
- Download ruby
o Find tar.bz2 version at:
https://ftp.ruby-lang.org/pub/ruby/ (check sub-directories)
o Download with curl: :
curl -sSL https://ftp.ruby-lang.org/pub/ruby/ruby-2.2.0.tar.bz2 -o ruby-2.2.0.tar.bz2
o Make sure you are downloading with the extension " .tar.bz2 "
- Download rubygems
o Find version at:
https://github.com/rubygems/rubygems/tags
o Download with curl:
curl -sSL http://production.cf.rubygems.org/rubygems/rubygems-2.4.6.tgz -o rubygems-2.4.6.tgz
Install dependencies :
- Disable automatic dependencies ("requirements") fetching using the following command.
rvm autolibs read-fail
- Manually download and install dependencies
o Get the list of dependencies using
rvm requirements
Installing Ruby :
Clean default gems:
echo "" > ~/.rvm/gemsets/default.gems
Clean global gems:
echo "" > ~/.rvm/gemsets/global.gems
Install Ruby:
rvm install 2.2.0 --rubygems 2.4.6 (this may require sudo password for autolibs)
Install any other Ruby versions you want similarly
Set default Ruby version: rvm use 2.2.0 --default
NOTE : The ruby and other packages should be placed in the " $rvm_path/archives/ " directory.
Installing gems :
There are multiple ways to install gems, we can download the gem files,
but the best way seems to be Bundler: http://bundler.io/bundle_package.html
Example installing rails gem:
Offline
--------
Create a directory:
mkdir gems; cd gems
Unpack gems:
tar xzf gems.tgz
Install bundler:
gem install bundler-1.8.3.gem
[ This needs internet, to avoid internet connection you need to install bundler gem using --local option with the bundler.x.x.gem file ]
Install gems:
bundle install --local
UNINSTALL rvm :
rvm implode --force
Then remove rvm from following locations:
rm -rf /usr/local/rvm
sudo rm /etc/profile.d/rvm.sh
sudo rm /etc/rvmrc
sudo rm ~/.rvmrc
Check the following files and remove or comment out references to rvm
~/.bashrc
~/.bash_profile
~/.profile
~/.zshrc
~/.zlogin
Comment-out / Remove the following lines from /etc/profile
source /etc/profile.d/sm.sh
source /etc/profile.d/rvm.sh
/etc/profile is a readonly file so use
sudo vim /etc/profile
You can find the installation method here also...
Reference : https://github.com/rvm/rvm-site/blob/master/content/rvm/offline.md
Update: Finally finally finally!!! We have it!
https://rvm.io/rvm/offline/
Full instructions for offline installation!
It should be enough to get copy of the sources and run:
./install
in the root of it,
for installing ruby you will need to get archives of ruby and rubygems to rvm/archives and set rubygems_version=1.8.24 in rvm/user/db
There is also another project I'm involved that will embed RVM and allow offline installation: https://github.com/railsinstaller/railsinstaller-nix
I am attempting to install RVM on Xubuntu and am having no luck getting the OS/terminal to recognize rvm as something that it can call.
I have been following the instructions here: http://beginrescueend.com/rvm/install/
I first call:
sudo bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
This seems to be executing correctly. I then run:
sudo echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
The text is appended to the end of the file.
Next I close out the terminal completely and reopen it. I try running:
type rvm | head -1
It responds:
bash: type: rvm: not found
If I try just calling rvm it responds:
The program 'rvm' is currently not installed. You can install it by typing: sudo apt-get install ruby-rvm
Clearly I am doing something wrong, I cannot seem to determine what that is. Thank you.
By using the sudo version of the install script, you have installed the multi user version of rvm, and then you ran the single user "sourcing" script with sudo...
When using the multi user version, rvm will not install into $HOME/.rvm, but in /usr/local/rvm.
Therefore you will have to use the multi user way to source the rvm script, and that is to add your user to the rvm group.
As shine already posted though, you probably didn't want to install system wide rvm to start with.
Don't do it with sudo. You have installed it for a root and you're not a root.
RVM should be installed in your home folder, you don't need superuser privileges for that.