Why do I get "write permission" errors installing Rails? - ruby-on-rails

When I use rvm use 1.9.2, I get Rails v3.0.0:
vikas#admin1-DL-H61MXEL:~$ rvm use 1.9.2 --default
Using /home/vikas/.rvm/gems/ruby-1.9.2-p320
vikas#admin1-DL-H61MXEL:~$ rails -v
Rails 3.0.0
When I use rvm use 2.0.0, I get Rails v3.2.13:
vikas#admin1-DL-H61MXEL:~$ rvm use 2.0.0
Using /home/vikas/.rvm/gems/ruby-2.0.0-p195
vikas#admin1-DL-H61MXEL:~$ rails -v
Rails 3.2.13
I need Rails v3.2.13 with Ruby 1.9.2.
When I used rvm use 1.9.2 --default and gem install rails -v 3.2.13, I got the following error:
While executing gem ... (Gem::FilePermissionError) You don't have write permissions into the /home/vikas/.rvm/gems/ruby-1.9.2-p320/bin directory.
This is the error I'm facing now.

The most likely reason you're getting the error:
(Gem::FilePermissionError) You don't have write permissions into the /home/vikas/.rvm/gems/ruby-1.9.2-p320/bin directory.
Is because, at some point, you used sudo or were running as root when you use RVM to install a gem. When that happened, the ownership of files and/or folders changed to root's permissions, which you can't override running as you.
You don't want to run as root, or use sudo EVER when running rvm or gem commands if you have a RVM installation to provide Ruby in a sandbox in your home directory.
To fix this, try this command:
sudo chown -R vikas ~/.rvm
That will use sudo to change ownership of all files in the ~/.rvm directory to your own account, from the "root" user. This will take at least a few seconds so let it run.
Once that has run, you should be able to switch to each of your Rubies and delete the installed Rails:
rvm use 1.9.2
gem uninstall rails
gem install rails -v 3.2.13
Then:
rvm use 2.0.0
gem uninstall rails
gem install rails -v [whatever version you want]
gem install rails -v

rvm use 1.9.2 --default Using /home/vikas/.rvm/gems/ruby-1.9.2-p320
gem install rails -v 3.2.13

rvm is software tool by which you can manage multiple version of rubies on your system.
for each ruby version you can create a gemset which is just a group of gems.
each ruby version you install has a 'default' gemset.
and it seems that you have installed rails 3.0 for ruby 1.9.2 and rails 3.2.13 for ruby 2.0
you can create your own gemset by command
rvm gemset create rails3
this will create a gemset named 'rails3' and to use it you have to do
rvm gemset use rails3
and in this gemset you can install any version of rails you want.
with command
gem install rails -v='3.2.13'
for more info see rvm doc.
https://rvm.io/

Related

After installing only rails gem version 5.0.0, the command 'rails -v' prints 'Rails 5.0.1'. Why?

I need to stick with Rails 5.0.0 for now. I'm using a gemset (rails500) and ruby-2.3.3 with rvm. I told rvm to use the gemset and uninstalled the other Rails version (5.0.1) from the gemset using the command 'gem uninstall rails'. After that I used the command 'gem install rails --version=5.0.0' to make sure my desired Rails is in the gemset.
Now when I do a 'rails -v' the response is 'Rails 5.0.1'. Why isn't it 'Rails 5.0.0'? When I do a "gem list | egrep '^rails '" the response is 'rails (5.0.0)'.
Related question: how can I be sure this version of rails is not 5.0.0?
Please follow this for setting the rails version you want:
rvm has nothing to do with rails. rvm is used to manage multiple ruby installations. And each of your ruby installations can be associated with multiple gemsets. For instance, say you have ruby 1.9.3 installed and you created two gemsets for ruby 1.9.3: gemsetA and gemsetB. If you tell rvm to use ruby 1.9.3 with gemsetA, that means:
Your ruby programs will be executed by ruby 1.9.3.
Your ruby programs can require any gem in gemsetA (which then allows your program to use the methods (or classes) defined in gemsetA), but any gems in gemsetB cannot be seen by your ruby program.
Here's a concrete example:
~$ rvm list
rvm rubies
ruby-1.8.7-p370 [ i686 ]
* ruby-1.9.3-p194 [ x86_64 ]
=> ruby-2.0.0-p0 [ x86_64 ]
ruby-2.0.0-p247 [ x86_64 ]
# => - current
# =* - current && default
# * - default
~$ rvm use 1.9.3-p194
Using /Users/7stud/.rvm/gems/ruby-1.9.3-p194
.
~$ rvm gemset list (This lists only the gemsets for the current ruby version)
gemsets for ruby-1.9.3-p194 (found in /Users/7stud/.rvm/gems/ruby-1.9.3-p194)
=> (default)
global
programming
rails3tutorial
rails4
~$ rvm gemset use programming
Using ruby-1.9.3-p194 with gemset programming
After I do that, my ruby programs will be executed by ruby 1.9.3 and any gems in the programming gemset can be required into my ruby program. You can use a shortcut to perform both those commands in one step:
rvm use ruby 1.9.3-p194#programming
You just combine the ruby version and the gemset with an '#' between them.
$ rails -v
Rails 4.0.0
This is because the current gemset contains the gem for rails 4.0.0. If you want to see $ rails -v output Rails 3.2.14, then you need to tell rvm to switch to a gemset that contains the rails 3.2.14 gem.
However, you can make rvm automatically switch to the proper rails version and gemset for your rails project. In your Gemfile, add a comment after the ruby version:
ruby '2.0.0'
ruby-gemset=railstutorial4_gems
Then whenever you switch to the directory containing your rails project, rvm will automatically switch the current ruby to ruby 2.0.0 and the current gemset to railstutorial4_gems. If you change directories out of your rails app, rvm will change the current ruby and the current gemset back to what they were.
I'm just a rails beginner, but here are the steps I use to create a new project, which are straight out of the railstutorial book (http://ruby.railstutorial.org/ruby-on-rails-tutorial-book)
1)
.../rails_projects$ rvm use # --create
e.g.
.../rails_projects$ rvm use ruby-1.9.3-p194#myapp_gemset --create
2)
.../rails_projects$ gem install rails --version 3.2.14
Because the current gemset is the myapp gemset, that command installs the rails 3.2.14 gem into the myapp gemset.
3)
.../rails_projects$ rails new myapp
.../rails_projects$ cd myapp
The current gemset is still myapp_gemset.
4)
.../rails_projects/myapp$ rails -v
Rails 3.2.14
In case anyone was wondering what the heck the following two gemsets are all about:
gemsets for ruby-1.9.3-p194 (found in /Users/7stud/.rvm/gems/ruby-1.9.3-p194)
=> (default)
global
rvm creates those two gemsets for every ruby version you install. After you install a ruby version, if you don't create a gemset yourself for that ruby version, and you install a gem, then the gem goes into the (default) gemset. And, if you want all your gemsets to contain a certain gem, you can switch to the global gemset and install the gem there.
Update: -------
To maintain compatibility with other ruby version managers, you can specify the ruby version and gemset name for your project in a different file rather than in the Gemfile:
$ cd ~/rails_projects/myapp
~/rails_projects/myapp$ echo 2.0.0 > .ruby-version
~/rails_projects/myapp$ echo myapp_gemset > .ruby-gemset
You'll still get the same automatic ruby version and gemset switching when you cd into your project's directory. See the rvm docs here.
The apparent answer is given by ryanjm at
https://github.com/rubygems/rubygems/issues/542
$ gem uninstall railties -v 5.0.1
is necessary after
$ gem uninstall rails -v 5.0.1

"Rails is not currently installed" Error

Hi i'm new to ruby on rails
I have 3 ruby version in my computer.
In a project i had to use rails 3.2.1 and ruby 1.9.2
So I switched using rvm use 1.9.2 in terminal. But after that my rails commands are not detected.
$ rails g model abc
The program 'rails' is currently not installed. You can install it by typing:
sudo apt-get install rails
Why is this happening? And how to solve this?
You may need to differentiate your gem set that contains that specific version of rails from the old ones.
rvm use 1.9.2#new_gem_set_of_yours --create --default
And then retry installing the 3.2.1 rails
gem install rails --version 3.2.1
Or specify the new rails version in your Gemfile and let Bundler take care of it
gem 'rails', '3.2.1'
and run bundle install.
Type in your terminal
gem install rails -v 3.2.1
if it does not work, first try
rvm install 1.9.3
then
rvm rubygems current
and repeat.

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.

Messed up Rails installation (OS X)

I had already installed rails 1.8.7, forgot about it, then installed 1.9.3 through RVM. I was getting weird errors, so I purged my Mac of the system version of Ruby and started again using RVM. So far I've
Installed Ruby:
rvm reinstall 1.9.3-p0
which ruby
/Users/User/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
Manually setup Rubygems
which gem
/Users/User/.rvm/rubies/ruby-1.9.3-p0/bin/gem
Tried to install rails
sudo gem install rails
Successfully installed rails-3.2.1
1 gem installed
gem list
rails (3.2.1, 3.2.0)
It says rails is installed, but which gem does not work, and when I try to use rails new I get:
-bash: rails: command not found
I'm definitely missing something here. The only explanation I can think of is that there are remnants of a previous ruby or rails install that's causing problems. Is there a way to start completely from scratch?
If you are using RVM, you should not use "sudo" when you install gems. That will install gems to your system ruby version (not on the RVM rubies).
First, set up default rvm ruby like
rvm use ruby-1.9.3-p0 --default
Then, install rails on it by running:
gem install rails -v=3.2.1
It's actually better to use gemsets so you can have different gems set for the same ruby version. Check here for more info.

Every time I close terminal rails defaults back to 2.3.5 from 3.0.3?

I'm going through the rails by example tutorial.
Its seems that every time I close terminal rails defaults back to 2.3.5 & I have to go through the process of installing 3.0.3 every time I open the terminal?
I installed rails using: $ [sudo] gem install rails --version 3.0.3
Has anyone experienced a similar issue? I've tried googling around and searching stack to no avail.
The problem is almost-assuredly RVM interpreting 2.3.5 as your default rails version in your default gem set. I ran into this problem myself when first experimenting with RVM. Try this:
rvm --default use 1.9.2 (or whatever you want your default ruby interpreter to be)
rvm gemset create rails-3.0.3
rvm use 1.9.2#arails-3.0.3 --default
gem install rails
That will:
Set your default ruby interpreter to the desired ruby version
Create a gemset for your Rails 3.0.3 install and make it your default gemset
Install rails
Once you close the terminal and open it back up, it'll load RVM's defaults, putting you back on Rails 3.0.3 again.
Try uninstalling the rails gem:
gem uninstall rails
If you are prompted to select a version, select 2.3.5 and leave the 3.0.3 version intact.
P.S: Are you using RVM? If not, I would highly recommend it.
I've had this problem using RVM, if you're using RVM do: $rvm 1.9.2 (or whatever ruby version you installed the rails 3 gem with).
Check the output of $ ruby -v when you seem to have access to rails3 and again $ ruby -v when you can only seem to get to v2.3.5. If it shows different versions of ruby then you most likley are using RVM.
#Ads If youre using RVM and you install rails using sudo like so
$ [sudo] gem install rails --version 3.0.3
youre doing it wrong. RVM depends on you using a ruby distro that was installed by RVM into your user directory. If youre using sudo, youre installing rails gem into your system-wide ruby.
So check that youre using the right ruby version by doing 'rvm info' and then do your 'gem install rails --version 3.0.3' without sudo

Resources