When I run gem install *some gem name* where does it install? - ruby-on-rails

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

Related

In a Ruby on Rails installation, what is causing webrick to be outdated and why `gem i webrick` can update it?

I have a new Mac computer and installed rails on it, and then I tried out the command
gem outdated
for some reason, it showed one of the gems outdated:
webrick (1.4.2 < 1.6.0)
I wonder why it is outdated on the first installed, and when I did
sudo gem install webrick
it actually installed 1.6.0 onto the system. Doesn't it require gem update instead of install to update something? How come install also updated it?
Not exactly, gem install GEM_NAME will install the last version available if you don't specify a version when installing, and you can have more than 1 version of the same gem on your machine.
you can run gem environment, and check where gems are installed, go to that folder and you will see both version gems folder there.
so when you create a rails project for example and add a specific version of a gem in the gemfile and another version on another project, you can have both without problems

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.

Is there a command in Rails that installs all your gems and dependencies?

I am learning Ruby on Rails and I find it annoying having to install and worry about gems and other dependencies for the apps I build . Does Rails have a way to install all your gems and dependencies for you ?
Yes. You have a file called Gemfile in the directory of your application.
Put all the gem you want to use in it.
And then just run bundle install to install all in one time (with dependencies) and later bundle update to update all your gem installed.
You can see Bundler: The best way to manage a Ruby application's gems and Ruby on Rails Tutorial for more informations.

What is the proper way to install a Ruby gem; Using RVM or Bundler?

I am following these instructions: https://github.com/phifty/agraph/blob/master/README.rdoc,
and there is a step to install a gem using this command:
gem install agraph
I am new to RoR, but I have RVM and Bundler. I am not sure which I should use. Should I install this using RVM or Bundler? What should be the command?
RVM is Ruby Version Manager. It lets you maintain separate installs of Ruby side-by-side without conflicts, easily. One of the requisites for doing this is keeping gems for each version of Ruby separate since the installers can "toggle" based on which version of Ruby you're running.
Gem is a command that lets you install gems. It's the core of the whole infrastructure – it doesn't call out to a lower-level "packager" to do its work.
Bundler runs "on top" of Gem. It makes managing gem versions easier, much like RVM does for Rubies (versions of Ruby). It'll automatically install gems that aren't installed, so you don't need to explicitly run gem install gem-name before running bundle (or bundle install).
Gem, Bundler, and RVM all cross paths if you start using RVM's gemsets. They allow you to further isolate and control your environment by creating a separate "gem environment" of sorts. The primary use for this is so that you can keep gems for different projects separate, which aids in managing versions. If you use Bundler, this isn't really as important or useful as in pre-Bundler days where Rails/Sinatra/etc. would require the most recent version of a gem.
Does that answer your question?
If you are using Rails 3 you should put the command in your application Gemfile
gem 'agraph'
then run bundle install. This will take care of dependency resolution and bundling the gem on your production servers when you deploy.
For RVM the only thing you might want to do is set an RVM gemset for your application. You can do this by creating a .rvmrc file in your application directory, which will automatically set the RVM ruby version and gemset when you enter into that directory. You should not manually install gems for your application using RVM.

Rubygems, Bundler and RVM confusion

I read "Relationships between Rubygems, Bundler, and RVM" before asking it again.
Well, there are many questions like this, but people who answered say they work with Rubygems, RVM and Bundler, and they have not explained how each of these work in isolation.
I am really confused with how the three work in isolation when we are installing gems. Please do not tell me how you work, which will help me, but I won't learn what is happening when we play with them.
My confusion can be broken down into these questions. Where is a gem installed when:
I just have Rubygems (without RVM or Bundler)?
Rubygems and RVM are installed?
Rubygems, RVM and Bundler are installed?
Please help me understand this stuff with either resources on the web or by your detailed answers.
To find out where gems are being installed to, run echo $GEM_HOME in a terminal.
When using RVM, gems are installed into your RVM install as it changes $GEM_HOME. Running echo $GEM_HOME now would show a path into your RVM install.
When Bundler is added to the mix, gems will either be installed in $GEM_HOME, or, if you specify a path when running bundle install will be installed to that path. To find out where a gem is through Bundler you can use bundle show gemname to get its full path.
Use gem env to list the gem paths in each context.
Without RVM gem env will report the system gem library paths.
With RVM gem env will report the RVM-managed gem library paths.
Bundler manages application dependencies and installs into the gem library in your environment. If you are using RVM + Bundler, the gems will be installed in the RVM managed gem directories. If you are using it without RVM, bundler will install gems in the system gem directories.
To find the path where a gem is installed use:
gem which gem_name
To find executables (like html2haml) use:
which executable_name
To avoid typing bundle exec html2haml which is recommended by the Bundler team, use my rubygems-bundler gem.
I'm also trying to understand how it works. The blog "Advice on using Ruby, RVM, Passenger, Rails, Bundler, … in development" helped me have a better overview.
BTW, it's a translation of a French article, the French version is better.

Resources