How to tell rvm where to install gem packages - ruby-on-rails

Normally, when I try to create a gemset using rvm,
it places any gems in $HOME/.rvm
However, on one machine when I run:
rvm use 1.8.7-p358#chris_gems --create
The command tries to write to the directory /usr/local/rvm/gems/ruby-1.8.7-p358
and as a result I get permission errors.
I tried search the web for command line arguments to "rvm" related to the install path
but didn't find anything after a 10 minute search (perhaps I'm sucking at Googling).
Also I tried setting GEM_HOME, GEM_PATH to my home directory.
But that didn't make a difference.
Any suggestions on how I can get rvm to install stuff in $HOME/.rvm
Thanks.

There are two ways to make it working:
add your user to rvm group - this will allow your user to write gemsets in system
run rvm user gemsets - this will make all new gemsets to be created in $HOME/.rvm

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.

Proper way to set up Rails app on local machine using existing Github repo and RVM

I've tried looking around the internet for a solution to this but to no avail. Every single time I try to set up a new app on my local machine I run into a ridiculous amount of issues with RVM. I decided its finally time I learn to do this right.
Basically I have been given permission to a Rails project in Github and I want to get it running properly on my local machine.
Generally speaking, what I have been doing in the past is this:
$ git clone git#github.com/projectpath
$ ls projectpath
$ bundle install
$ rake db:setup
And cross my fingers. Sometimes it works, other times I have to use RVM to change rubies and redo bundle install. Today, everything is breaking and I keep running into problems like this:
$ 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.
I have a feeling that I am not setting up these apps correctly and also not using RVM as its supposed to be used - basically I believe that my fundamental understanding of RVM is wrong. I would very greatly appreciate it if someone could outline the proper way to do set up a new app using a remote Github repo, as well as explain the proper way to use RVM to get this new app running. Thanks in advance!
I think your life would be easier if you used RVM's gemsets. One gemset per rails application. This keeps everything nice and isolated from each other.
So... something like this...
# install bundler in the global gemset as you want it available everywhere.
$ rvm use #global
$ gem install bundler
# create a project specific rvmrc/gemset.
$ cd /folder/containing/your/github/repo
$ echo "rvm use #myapp" > .rvmrc
$ cd into/rails/root/for/your/app
$ bundle install
At this point you're installing the gems into the 'myapp' gemset, totally isolated from your other gems. There's a new file name for .rvmrc, but I can never remember what it is. .ruby-version or something.
You may also need to create the gemset before it can be used. See the RVM docs for how to make that happen automatically.
Do these cloned projects have files named
.ruby-version
and
.ruby-gemset
in the top level directory? Those files instruct rvm (and other versioning systems) to use a particular ruby version and gemset combo. It could be sometimes you cd into a cloned directory that references the name of a gemset you've already created, in which case bundle and rake work, and sometimes it references a gemset you don't have, in which case you get mysterious blowups.

How do I set 'global' as default gemset?

In RVM every time I restart it says gems aren't found, because all of them are installed in my 'global' gemset.
How can I just set this to be the default so I don't need to switch to that gemset everytime?
I actually looked through documentation for some time and didn't see anything, but I found this from stack overflow by searching a bunch of different things.
First run rvm list to see your rubies
Then run rvm gemset list to see your gemsets
Finally, run rvm use <desired-ruby-version>#<gemset> --default
For example:
rvm use ruby-1.9.3-head#global --default

Why am I seeing reference to a gemset of another project in my current project?

I recently created a new Rails project, and I believe I created a gemset for it before generating the app.
But when I encounter an error I get a message like this:
File /.rvm/gems/ruby-1.9.3-p194#project_1/gems/activerecord-3.2.8/lib/active_record/relation/finder_methods.rb
Even though I am in project_2. So in theory that should be ruby-1.9.3-p194#project_2 and not project_1.
What can be causing this and how can I fix it?
Thanks.
P.S. I am using RVM.
Edit 1:
I ran rvm gemset list and this is the output:
project_2$ rvm gemset list
gemsets for ruby-1.9.3-p194 (found in /Users/marcamillion/.rvm/gems/ruby-1.9.3-p194)
project_1
=> project_2
project_3
Edit 2:
I just ran gem install rails in my project_2 directory after I created the .rvmrc file for that project after verifying that it is indeed using the gemset for that project specifically. However, when I generate the error again, I am still seeing a reference to the gemset in project_1.
Edit 3:
The output for rvm current:
$ rvm current
ruby-1.9.3-p194#project_2
Edit 4:
Although, when I run rvm current in the same terminal window as my rails s I see:
$ rvm current
ruby-1.9.3-p194#project_1
So how do I set the gemset across all terminal windows for right now, and in the future?
You need to tell RVM which gemset to use. Try this:
rvm gemset use project_2
If that works, then you may wish to create a .rvmrc file in project_2's root directory so that it automatically switches to that gemset when you enter the directory:
cd /path/to/project_2
rvm --rvmrc --create 1.9.3#project_2
That'll create a .rvmrc in /path/to/project_2. cd out of the directory and back in, and it'll prompt you asking if you trust the .rvmrc file. By default, it'll only ask you the first time.
Edit:
It is important to note that when creating a new .rvmrc, you need to cd out of the project directory in all open terminal sessions (including rails s and rails console). Otherwise the app will continue using the gemset from project_1.

Uninstalling rails and gems, getting error "cannot uninstall, check 'gem list -d ...'

I'm going to start with the usual noob line, "I'm new to rails". Oh, and I'm running Mac OSX 10.6.4
I've been following a bunch of guides to get set up, specifically these two here and here. The guides are great, the reason I'm using the second one is because of RVM and the reason I'm using the first is for MYSQL.
Anyway, when I started, I wasn't following the directions completely and so after I installed RVM, for some reason I installed rails with sudo gem install rails -v 2.3.8 because thats the version I need. So... I realized I was using the system ruby, and wasn't taking advantage of RVM. What I did now was install Ruby 1.9.2 so I can install rails 3 and test it out, and I also installed 1.8.7 and rails 2.3.8 so I can use it for what I need it.
Now, I'm trying to uninstall the gems from the system Ruby, but whenever I try to I'm getting this error:
ERROR: While executing gem ...
(Gem::InstallError)
cannot uninstall, check 'gem list -d
whatever gem I try to uninstall'
Any ideas on how to remove rails and all these gems? I just want to start from scratch with RVM.
UPDATE:
By running the command gem list -d rails I've located the gems in /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/18. Should I delete them manually?
SOLUTION!! I still don't understand why this happened, I'd love if someone could explain. Why was the path non-existant? What caused this error?
Also, I want to mention that the solution I linked to has a comment saying that the question is a duplicate. However, the original has a different solution and did not help me (though its the basis to finding this answer). Simply deleting the gems manually in finder would not remove them from the gem list.
Without further ado - it turns out that when trying to uninstall the gem, it can't locate its path (I think the problem is because of installing with sudo, but I might be wrong). What you need to do is (you have to do this one by one for each gem, or at least I had to):
gem list -d 'name of gem' and note the "Installed at:" location (in my case, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8)
sudo gem uninstall 'name of gem' -i 'the path noted above' (ex. in my case, sudo gem uninstall rails -i /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
Some gems still might not uninstall returning a permissions error. If this is the case, what you need to do is create a folder /bin, in the path above. (in my case, mkdir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/bin
Continue uninstalling as in step 2, still using the original path (/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8).
Now all uninstalls should work!
Two things you should note when using rvm:
You should NEVER use sudo to install gems, just do a gem install xxx
You can not uninstall gems installed in the global gemset from within another gemset. You should switch to the global gemset and uninstall from there:
rvm gemset use global
gem uninstall xxx
execute this either in irb or in a script proper:
`gem list --no-versions`.split("\n").each do |gem|
`gem list -d #{gem}`.gsub(/Installed at(.*):.*/).each do |dir|
dir = dir.gsub(/Installed at(.*): /,'').gsub("\n", '')
system "gem uninstall #{gem} -aIx -i #{dir}"
end
end
try this way :
sudo apt purge rails
ok i see....
at this point, if you're in the terminal, it shouldn't take but a few minutes to reinstall the whole shebang
I suspect you might not be in the correct rvm name that has the gems you're trying to install so thats why i'd suggest reinstalling rubygems and building you're core gems from the beginning in your Global rvm gemset name.
A more generic answer to delete all gems for older versions of gem 1.8.
gem list --no-versions | xargs sudo gem uninstall -aIx
I was using RVM to manage my gemsets and had not selected the gemset. I wasn't that I had selected the wrong gemset, it was that I hadn't selected the gemset at all. A lovely way to spend the bulk of an hour of my first morning back after my summer holidays!

Resources