gem install trouble - ruby-on-rails

I have a weird trouble, i've updated the .irbrc file to make better looking, for this I
installed awesome_print, wirble and looksee gems, check them by gem list - every gem is there.
And when i run rails console i got this:
Cannot find awesome_print gem. Please run 'gem install awesome_print' to install it.
Cannot find wirble. Please run 'gem install wirble' to install it.
Cannot find looksee. Please run 'gem install looksee' to install it.
I've no idea why it happen. I have rvm on my system but I don't think it causes the problem.
Thanks.

To install gems in Rails 3, add them to your Gemfile
For instance:
gem 'awesome_print'
gem 'wirble'
gem 'looksee'
Then run bundle install.
It's also a best practice to create a gemset with rvm per-project to isolate dependencies among projects.
To do this, in your Rails root directory run: rvm --create --rvmrc 1.9.2#myproject (substitute 1.9.2 with whatever version of Ruby you want to use).
After creating the gemset, rerun bundle install.
You'll notice an .rvmrc file has been created, which makes sure whenever you cd to that directory, the "myproject" gemset will automatically be used. Add this to version control so other developers get the same effect.

Related

Can't install ruby on rails in ubuntu gnome 15.10

I am trying to install ruby on rails. I'm at version 2.3.0 for ruby and gem version of 2.5.1.
When I run the command gem install rails I get an error that says:
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/local/lib/ruby/gems/2.3.0 directory.
How can I fix this?
gem install tries to put files in "system-wide" directories. These are protected, such that only the root user can write into.
You have at least three possibilities:
sudo gem install ..., this will write the gem files into /usr/local/lib/ruby/gems/2.3.0
gem install --user-install, this will install the gem "locally" in your users home directory
apt-get install ruby-rails (not sure about the package name), which will install the ruby on rails version maintained by your distributions maintainers (Canonical).
install and use rvm or rbenv (and there might be other options). Afterwards gem install will usually just work and install the gems for your user only
While the rvm setup might be a tiny bit confusing for newbies, I recommend using that approach. It will make updating and installing ruby, gems and different versions of it really easy.

How to move or uninstall gems from default System Ruby folder to RVM?

I have so many issues trying to update from Rails 3.2 to Rails 4.1 following the guide that I decided to uninstall Ruby, Rails and RVM (with all its gems) and start over.
RVM and Ruby Gone. $ rvm remove
But still have a bunch of GEMS that I previously installed.
$gem list
As suggested on this answer, to remove all gems do:
$for i in `gem list --no-versions`; do gem uninstall -aIx $i; done
But I bump again on the error:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory
This is so frustrating! Using sudo does not make the fix either.
Even if I try to uninstall one by one, the system wont let me:
$rails uninstall
Could not find gem 'pg (~> 0.17.1) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
Why do I need another Gem to uninstall a Gem?!
Try
for i in `gem list --no-versions`; do sudo gem uninstall -aIx $i; done
This SO question has some ideas: getting rid of ruby gems that won't die
The answer to this SO question has step by step instructions to set it up properly: Removing Gems errors

When I run gem install *some gem name* where does it install?

As the question states - where does the gem install?
Is it installing within the app directory that I'm working in (i.e. user/sites/sample_app)? Or is it being installed on my computer? If the latter where exactly?
Thanks!
gem install process
first download gem and save desktop
1.next step open command prompt and set location that means c:/desktop> gem install --local "gemname"
2.next step com to rails consoler and type $bundle install --local.
3. type the gem name on gem list
I have two questions:
Where do you install your ruby?
Did you use RVM or rbenv?
Now I will explain your question using my situation as an example.
I use RVM to manage rubies on my mac os.
now the ruby install in path
/Users/pin/.rvm/rubies/ruby-2.1.1
and these will be a gems directory under .rvm path. In this directory,
/Users/pin/.rvm/gems
there are many gems group, I have a group named
ruby-2.1.1#global
which is used by the default ruby version.
This is a directory and there will be a gems directory under it.
/Users/pin/.rvm/gems/ruby-2.1.0/gems
In this directory, you will find all of the gems you installed using cmd
bundle install
If you don't use ruby version management tools like rvm or rbenv, you may find the gems
around your ruby path. If you still can't find them, you can post the details of how you
install the rubies and other system configs, so that we can discuss here.
If you are using rvm then its get installed in
/home/user/.rvm/gems/ruby-version#global/ or /home/user/.rvm/gems/ruby-version/
If you are using specific gemset for gems then
/home/user/.rvm/gems/ruby-version#gemset_name/
If you want to know where gem is installed use gem which *gem_name* e.g.:
gem which rails
If you installed your gems with bundle install use bundle show *gem name* e.g.:
bundle show rails
Gems
If you use gem install x, you're adding the gem to the local ruby version on your system. This is a system-wide installation, and will be stored in your rubylib/ruby/gems dir:
The install command downloads and installs the gem and any necessary
dependencies then builds documentation for the installed gems.
Bundler
Using the bundle install command (when you have a Gemfile & use bundler), you basically tell bundler to install the gems relative to your specific applicaiton:
Bundler makes sure that Ruby can find all of the gems in the Gemfile
(and all of their dependencies). If your app is a Rails 3 app, your
default application already has the code necessary to invoke bundler.
If it is a Rails 2.3 app, please see Setting up Bundler in Rails 2.3.
For example, if you have a Rails 3.2 app, and a Rails 4.1 app on your system, using bundler allows you to instal the dependencies (gems) for each app independently
If you use gem install x, it will install the gem for all applications, and should only be used for things like rmagick and the database connection gems

RVM project specific gems

I've set up an RVM environment and installed Bundler and Rake.
In my Project I've got a Gemfile, when I run bundle install the gems get installed in the project folder that I've specified. But when I run gem list I don't see the gems installed by Bundler.
Why is that?
Thanks for your help
Edit:
And also I've definied the rails gem and it's version in the project Gemfile so I never ran gem install rails
Edit 2:
I've ran gem install rails. When I run rails -v outside my project I get 3.2.12, inside my project folder I get 3.2.11 which is the version defined in my Gemfile.
But why? Why did I have to install Rails globally?
In your .rvmrc write following code:
rvm use <ruby_version>#<project_name> --create
In my case ruby_version is ruby-1.9.3-p194
Once you navigate to your project path, run bundle install to install all the gems specific to your project.

Get confused of some rails concepts, needs some explanations

I got confused of some Rails' concepts like: gemset, rubygems, bundler . I have following three questions:
1. After I installed the RVM tool, what are the correct steps to setup the development enviroment for creating a rails project (say rails v2.3 project)
2. What is the difference between "gem install XXX" and "bundle install"? Can I understand it in the way that "bundle install" install all gems needed in the app at once while "gem install XXX" only install the specified "XXX" gem ? Are there any other difference? Why not use bundler to install specific rails then?
3. If I want to use rails v3.0 for project_one, and use rails v2.3 for project_two. How to create the two projects with the specific rails versions? How about different ruby versions for different projects? Do I only need to specify the needed version in Gemfile or install the needed version under the project path?
RVM allows you to create different gemsets alongside different ruby versions.
You can install different versions of ruby with rvm install.
rvm install 1.8.7
rvm install 1.9.2
rvm list known will tell you the available ruby implementations you can install.
Say, you have two projects: project_one and project_two, and both of them have different gem dependencies. So you'll want to create two empty gemsets with, say, Ruby 1.9.2.
rvm gemset create 1.9.2#project_one
rvm gemset create 1.9.2#project_two
To use project_two's gemset, you can use rvm use to select the gemset.
rvm use 1.9.2#project_two
You can also add the above command into a file called .rvmrc in the root path of your rails application, which rvm will load automatically whenever you cd into the app's root directory.
If you want to use Rails 2.3.8 for project_one,
rvm use 1.9.2#project_one
gem install rails -v 2.3.8
and Rails 3.1.0 for project_two,
rvm use 1.9.2#project_two
gem install rails -v 3.1.0
The difference between gem install and bundle install is that gem install installs only the specified gem into your gemset, while bundle install installs all the gems located in your app's Gemfile.
1) If you have a rvm setup I propose add in in your app file .rvmrc
and in that file:
rvm --create ree-1.8.7-2011.03#myappname
This will alway use specify version of ruby (in that case 'ree-1.8.7-2011.03') and all gems will be installed in rvm gemset named: myappname. This file will always make sure every time you go to that folder from bash_console it will point rvm to correct environment.
2) If you have rvm setup then:
gem install XXX creates gem in specify rvm gemset or if not global rvm gemset
sudo gem install XXX will add gems to you Global gems
Like you said, you should always use Bundle install, and group gems for development,test, production.
3) This can achieve like I said in point 1) just create this file in your app

Resources