Rails commands only work on one terminal - ruby-on-rails

I installed Ruby and then RVM, and then configured Rails.
It all works when I call it from the original terminal. But when I try to call various commands from new terminals, the system just gives an error message such as this one:
$rails server
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
Why does that happen? Is there some global variable which needs to be set? I am using Ubuntu by the way.

Example of how/where gems are installed:
rvm use 1.8.7
ruby -v # 1.8.7 returned
rvm gemdir # some directory returned
gem install rails # (installed to the directory returned by `rvm gemdir` in 1.8.7)
rails -v # some version returned
rvm use 1.9.2
ruby -v # 1.9.2 returned
rvm gemdir # some directory returned
rails -v # Error if not installed, else version is shown
gem install rails # (installed to the directory returned by `rvm gemdir` in 1.9.2)
rails -v # some version returned
Now, the Rails gem is now installed in 2 directories (1 for each of the Ruby versions)
Now in order to set a default version of Ruby (instead of typing rvm use every time you open a terminal), you can run:
rvm use 1.9.2 --default
See the documentation for more information about default.
Some other commands:
Default ruby rvm list default
All Rubies: rvm list
Also note do not use sudo with RVM!
Hope that clears things up!

It's also important to note that gnome terminal needs to have access to the login shell. This can be configured on Ubuntu 12.04 by right-clicking on your terminal pane, clicking Profiles > Profile Preferences selecting the Title and Command pane and toggling the option Run command as login shell.
Source: RVM + Gnome Terminal

After setting rvm default,
bash --login
did the trick for me.

i solve this problem configuring the terminal on ubuntu to 'Run command as login shell'
follow this simple tutorial
https://rvm.io/integration/gnome-terminal

Related

When Rails app is accessed from a new terminal, all gems are deleted

This bizarre...I replaced the hard drive on my computer and reinstalled Ubuntu 14.04, and cloned my Rails app. I set it all up, ran bundle install, and everything went fine.
But when I open a new terminal and access the app from it, the new terminal thinks that my app doesn't have any gems installed. Even rails -v returns
$ rails -v
The program 'rails' can be found in the following packages:
* ruby-railties-3.2
* ruby-railties-4.0
Try: sudo apt-get install <selected package>
and bundle install returns
Your Ruby version is 1.9.3, but your Gemfile specified 2.0.0
But on the terminal I used to set up my app (both terminals are open at the same time) if I run rails -v I get the normal output "Rails 4.0.10
", and bundle install executes normally.
I'm pretty sure if I were to quit out of the terminal I used to set it up, all the changes I've made to my app would be reverted for good, but I don't want to test that theory.
How is it possible for two simultaneous terminals to see a project differently??
Output of rvm list for BOTH terminals
$ rvm list
rvm rubies
=* ruby-2.0.0-p643 [ x86_64 ]
# => - current
# =* - current && default
# * - default
UPDATE
I closed all open terminals and opened up a new one, and reinstalled RVM and ruby. No matter how many times I do this, ruby -v always returns
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
but rvm install 2.0.0 returns
Already installed ruby-2.0.0-p643.
To reinstall use:
rvm reinstall ruby-2.0.0-p643
Your rvm setup isn't right. A new terminal is running the rvm shims (paths to rvm ruby and gems), and the old terminal is pointing to a different ruby version, maybe even the system ruby; or vice versa.
Close all terminals, start a fresh one, check to see if RVM is set up correctly with the bash hooks; then bundle install.

Facing difficulty in Installation of Interactive Ruby shell and ruby in ubuntu 13.04 and getting started with rails

Accidently I have installed both versions of ruby on my system and now the default version is set to
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
but I need to set the default version to 2.0.0...
for this I used the command
$ rvm 2.0.0p294 --default
but it says rvm is not currently installed though I installed it, typing various commands(via google) .
Also I want to install an Integrated Ruby shell in ubuntu 13.04, do suggest how to do it.
I have also installed Aptana Studio on my system, now how should I get started with it.
Finally, the last problem is tell me how to check whether rails is currently installed in my system or not...
Thanx in advance!!
to use a gemset try writing
rvm use ruby_gemset_version
to check the rails version try to type rails -v
you have to install RVM (ruby version manager), then you have control to use any specific versions of ruby, and coming to rails you have to manually install rails gem once you have installed rvm and selected a version.
This would be helpful to install rvm
https://rvm.io/rvm/install
After installation you have to install ruby versions.
Then you can use the following cmd
$ rvm use 2.0.0
to use ruby 2.0.0
Thank you.
Go to this http://rvm.io/rvm/install It has instruction to install and cofigure RVM. It is dependant on CURL lib. So make sure you have curl installed in your system, if not then the command is
#sudo apt-get install curl
Once it is intalled and configured properly.
On Ubuntu:
GoTo Terminal > Profile Preferences > Title and Command > Set checkbox for (Run command as login shell)
Install rubies using rvm install.

Ruby version conflict using rvm

I have some conflicts of ruby version.
When I run ruby -v in my terminal (in osx), I get the 1.8.7 version. I tried to upgrade ruby version, installing rvm, with this command curl -L https://get.rvm.io | bash -s stable --autolibs=3 --rails. Then I tried to run rvm install ruby-1.9.3-p362, and I was told that rvm was not a found command. So I ran source /Users/host/.rvm/scripts/rvm install ruby-1.9.3-p362, this worked and when I run in my bash ruby -v, I get ruby 2.0.0. But it seems to be related to my current terminal session since when I run ruby -v in another session, I always get 1.8.7 version. How can I set on my .bash_profile (or elswhere) the right version of ruby (and of rails) ?
RVM allows to install multiple versions of ruby on a single *nix box. Each ruby version is kinda sandboxed from another one. For the first time, you will need to specify a default version of ruby. This will be needed only for the first time.
rvm use 1.9.3-p290 --default
To switch to another version, simply type:
rvm use 1.9.2
Rails is just a gem. To get the most out of RVM, create a gemset and install all gems for one ruby version within one gemset. i.e. one gemset per ruby version.
This works like :
rvm gemset create my_gem_set
Gemset 'my_gem_set' created.
rvm gemset use my_gem_set
You can also use .rvmrc file in your project directory to 'load' just the required gems for your app. There is one .rvmrc per project. You can refer rvm.io for docs on rvmrc
You should set the default ruby via rvm: https://rvm.io/rubies/default/
rvm --default use <ruby_version>
You need to enable login shell in your terminal emulator, here is example how to set it up in gnome-terminal https://rvm.io/integration/gnome-terminal/

RVM bundler installed ERROR: Gem bundler is not installed, run `gem install bundler` first

I get to work with a new project and it's based on ruby 1.8.7, I'm using rvm to manage my ruby versions and I have installed 1.8.7 and 1.9.2.
The thing is when I do:
rvm use 1.8.7
and try to run:
bundle install
I get:
ERROR: Gem bundler is not installed, run `gem install bundler` first.
I've installed bundler 5 times and even after that it says it's not installed. What can cause this? Bundle even shows up at my gem list.
update from comments:
The ouput of the which ruby && which gem is:
/home/username/.rvm/rubies/ruby-1.8.7-p371/bin/ruby
/home/username/.rvm/bin/gem
Output of "env | grep -iE 'ruby|rvm|gem' | sort":
GEM_HOME=/home/username/.rvm/gems/ruby-1.8.7-p371#global
GEM_PATH=/home/username/.rvm/gems/ruby-1.8.7-p371#global
IRBRC=/home/username/.rvm/rubies/ruby-1.8.7-p371/.irbrc
MY_RUBY_HOME=/home/username/.rvm/rubies/ruby-1.8.7-p371
PATH=/home/username/.rvm/gems/ruby-1.8.7-p371#global/bin:/home/username/.rvm/rubies/ruby-1.8.7-p371/bin:/home/username/.rvm/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
RUBY_VERSION=ruby-1.8.7-p371
rvm_bin_path=/home/username/.rvm/bin
rvm_delete_flag=0
rvm_path=/home/username/.rvm
rvm_prefix=/home/username
rvm_ruby_string=ruby-1.8.7-p371
rvm_sticky_flag=1
rvm_use_flag=1
rvm_version=1.17.7 (stable)
Unistalled and installed 1.8.7 via RVM
ran:
rvm install 1.8.7 --verify-downloads 1
and it worked.
It looks like you're probably running the wrong version of gem. In my RVM setup, using the shell command overrides recommended with RVM (source "$HOME/.rvm/scripts/rvm" in your .bashrc or .zshrc or another suitable startup file), gem is normally a shell function. It does some RVM magic under the covers and then runs the real gem command. In my case, both ruby and gem run out of the same version directory:
/home/jim/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
/home/jim/.rvm/rubies/ruby-1.9.3-p327/bin/gem
Make sure you're sourcing the RVM startup script.
Your PATH looks ok. Make sure you have a /home/username/.rvm/rubies/ruby-1.8.7-p371/bin/gem command. If not, you may have to reinstall ruby-1.8.7.
Running rvm current will show which Ruby version and gemset are being used. Make sure there's a gem in the path that matches the Ruby version.
rvm install ruby-1.9.2-p320
use this and remember close all terminal
and in edit-> profile preferences--> title and command -->> check (Run command as login shell)

RVM won't install Rails to system

I've tried the following commands:
rvm system gem install rails
rvm system install rails
rvmsudo gem install rails
sudo gem install rails
After one of these commands, I get a message telling me to run sudo gem install rails. But it doesn't work.
I had no problems before to install rails on rvm 1.9.2 the Mac OSX 10.6.8 version.
Could anyone help me with that?
If you've installed rvm successfully, test with rvm info so that it returns output then you just need to do gem install rails to install rails into the ruby version you are using with RVM - no sudo required. Have I misunderstood?
First check either rvm install properly or not using this command
rvm --help
then install rails by this command
gem install rails -v=3.2.1
Or any version you want..
If you don't have ruby 1.9.3 then use:
$ rvm install 1.9.3
or you may start from this:
$ rvm use 1.9.3
$ rvm gemset create rails313
$ rvm use 1.9.3#rails313 --default
$ gem install rails -v 3.1.3
note: I use 1.9.3 as an example you can use other ruby version also.
Follow the documentation. Make sure you've got the necessary system requirements via rvm requirements. Unless you've got some bizarre user permissions in $HOME, there is no reason to use sudo w/ rvm on your system.
make sure you have installed build_essentials, also try rvm requirements, which gives all dependencies, install all using rvmsudo command
See also: Installing Ruby on Rails - Mac OS Lion
First check whether all dependencies are satisfied by running:
$ rvm requirements
next:
$ rvm install ruby
next:
$ gem install rails
Note: You may have to use sudo or rvmsudo before the commands depending on whether its system-wide install or user specific.

Resources