RVM and Rails (3.2) Path Problems OSX - ruby-on-rails

I have rails and RVM installed on OSx 10.7.4
If I do this
$ cd ~/
$ rails -v
I get
$ Rails 3.2.3
Now if I go into a rails application with
$ cd ~/rails-project/
Using ~/.rvm/gems/ruby-1.9.2-p320 with gemset ourgemset
The .vmrc file in the rails app looks like this
rvm use --create 1.9.2#ourgemset
However when I try and use rails now I get
$ rails -v
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.
My ~/.bash_profile has this line at the end of it (and these scripts exist)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function
I've no idea why this is happening or where to look to solve it.
EDIT:
On further investigation if I do the following
$ rvm use default
Using ~/.rvm/gems/ruby-1.9.3-p194 with gemset anothergemset
Now rails works fine. If I switch back to
$rvm use ruby-1.9.2-p320
I can't use rails anymore. Help!

Your global env has Rails but your gemset does not contain the rails gem. So when you are in cd ~/rails-project/ run the command:
gem install rails
it will install the gem to your rvm gemset.

Related

Ruby/Rails is contradicting itself, what should I do?

I am trying to learn Ruby on Rails, I have installed Ruby, ruby -v gives ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-darwin18] and I have installed rails using gem install rails however when I run rails -v I get the following dialogue.
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.
I then do as the prompt asks and run sudo gem install rails (inputting my pw) which gives me;
Successfully installed rails-6.0.2.2
Parsing documentation for rails-6.0.2.2
Done installing documentation for rails after 0 seconds
1 gem installed
to check that Rails has installed properly I run rails -v again, and again 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.
Am I missing something very obvious?
The best way to manage your Ruby/Rails environment is to use a tool like rvm and never use the system Ruby/Rails. Changing Ruby/Rails versions globally for all your apps will most likely break them, so you want each app to be locked to a specific Ruby/Rails version and only upgrade each one manually.
Start by installing RVM locally for your user:
\curl -sSL https://get.rvm.io | bash -s stable --ruby
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
source $HOME/.rvm/scripts/rvm
Make a directory for your app.
mkdir my_rails_app && cd my_rails_app
Make a local .ruby-version and .ruby-gemset for each project:
echo 2.6.5 > .ruby-version
echo my_rails_app > .ruby-gemset
rvm reload
Then install rails only for the specific gemset "my_rails_app" (I usually give each app its own gemset).
gem install rails
rails new my_rails_app .

Unable to use GEM_HOME in radrails

I have setup Radrails on my linux machine. I dont have root privileges on this machine and I also cant edit the ruby installation folder. I have set GEM_HOME and GEM_PATH to a location where I have privileges. I am running radrails from the terminal where I have set these variables. Does Radrails is recognize the gem location?
Also I am not able to start the Webrick server using Radrails. The server always is in stopped state and the console output is blank. I am not able to fix this since I dont see any errors.
thank you!
Use rvm or rbenv to change ruby and gem space to another one. If you will begin usage of the them do the following:
Install rvm with ruby:
$ \curl -sSL https://get.rvm.io | bash -s stable --ruby
or install rbenv, and then install ruby, and make it global:
$ \curl https://raw.githubusercontent.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash
$ rbenv install 2.1.4
$ rbenv global 2.1.4
Install the rails without documentation into the general gem space:
$ gem install rails --no-ri --no-rdoc
Enter to the project, create two files .ruby-version with just installed version of ruby (in example 2.1.4), and .ruby-gemset with name of your project:
$ cd project-folder
$ echo "2.1.4" > .ruby-version
$ echo "your-project-name" .ruby-gemset
Fix Gemfile with newly intsalled version of ruby adding a line:
ruby '2.1.4'
Reenter to the project folder, and rvm will generate its wrappers:
$ cd .. ; cd project-folder
Issue gem installation:
$ bundle install

downloaded ruby on rails but it wont run commands

I downloaded ruby on rails on ubuntu 12.10 through this tutorial http://technical-feeds.blogspot.ca/2013/02/how-to-install-ubuntu-and-ruby-on-rails.html.
I did everything and it worked fine.
I checked ruby -v and it came back as ruby 2.0.0p0. I also checked rails, rubygems and git they came back good.
Then I closed the terminal and opened a new one and tried to check the version but this came back for ruby:
bimbola#ubuntu:~$ ruby -v
The program 'ruby' can be found in the following packages:
* ruby1.8
* ruby1.9.1
Try: sudo apt-get install <selected package>
And this came for rails:
bimbola#ubuntu:~$ rails -v
The program 'rails' can be found in the following packages:
* rails
* ruby-railties-3.2
Try: sudo apt-get install <selected package>
git is still fine though
bimbola#ubuntu:~$ git --version
git version 1.7.10.4
You need to state which version of ruby you want to use. Try this:
rvm use 2.0.0
You can also set a particular version of ruby to be used as default as shown below
rvm --default use 2.0.0
RVM (Ruby Version Manager) allows you to install multiple versions of ruby and use any one of them at a time as according to your whim.
To see all the available ruby versions on your system try this:
rvm list
Add a line to your bashrc to load rvm automatically: (execute in Terminal)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> .bashrc
or load rvm manually:
source "$HOME/.rvm/scripts/rvm"

Rails commands only work on one terminal

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

RVM is currently 1.9.2, want to run my app on 1.8.7, what should I do?

I'm new to RVM.
So I have a RVM setup that has ruby 1.9.2 with rails 3.
I want to know test the app in 1.8.7 with rails 3, what should I do?
Just change RMV's to 1.8.7 and navigate to the directory where my Rails app is?
Do I have to run bundle install again?
That's correct, assuming you already installed 1.8.7 with RVM: rvm install 1.8.7, and loaded the rails 3 gem (remember, never use sudo with rvm). Then it's just:
$> rvm 1.8.7
$> cd /path/to/myApp
$> bundle install
$> rails server
Update: as tinifni points out in the comments, you may want to create a new gemset for your 1.8.7 installation to keep your gems separate from those already installed:
$> rvm gemset create rails3dev
$> rvm 1.8.7#rails3dev
$> cd /path/to/myApp
$> bundle install
$> rails server
Of course, there's all this and more in the the official RVM documentation

Resources