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.
Related
I installed rails via a Gemfile and bundle install:
Gemfile
source "https://rubygems.org"
gem "rails", "5.0.6"
the gem appears to have successfully installed according to success message. However it is still not available from the command line even after a restart.
$ rails
The program 'rails' is currently not installed. You can install it by typing:
sudo apt install ruby-railties
You will have to enable the component called 'universe'
I am using rbenv (required) and have a number of utilities in /.rbenv/shims/ (gem, rake, bundle, etc.) but not rails... so I don't know where it got installed.
gem env returns:
GEM PATHS:
- /home/user/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0
- /home/user/.gem/ruby/2.5.0
but I don't see those packages there. I'm guessing it needs to be on the path, but I don't know where it is. The solution needs to work while installing with a bash script.
just add bundle exec
bundle exec rails
When you use rbenv and you install Ruby on Rails then you might need to run rbenv rehash to make the rails command available.
From the docs:
Installs shims for all Ruby executables known to rbenv (i.e., ~/.rbenv/versions/*/bin/*). Run this command after you install a new version of Ruby, or install a gem that provides commands.
after I read your problem, I guess that you used rbenv and you didn't run rbenv rehash, so you can do it as following below:
gem install railties
rbenv rehash
So, I was running rbenv rehash and setting the environment variable. However, the new env variables were not available until after a restart. Using the full path to /.rbenv/shims/rake solved the problem.
I'm learning Rails with tutorials from Ruby on Rails by Michael Hartl: https://www.railstutorial.org/book
I used the following command to generate a controller:
rails generate controller StaticPages home help
Which generates the following error regarding version conflicts:
check_version_conflict': can't activate bundler-1.12.4, already
activated bundler-1.13.0.pre.1 (Gem::LoadError)
I don't know which bundler version to use. The current version of bundler is: 1.13.pre.1
The following command continued failing due to about five gem dependencies that failed to install automatically, which included listen and nokigiri.
bundle install --without production
I tried installing the dependent gems manually, but I'm still having issues.
How do I resolve the check_version_conflict issue with Bundler when generating Rails controllers?
I'll accept an answer that instructs removing current Ruby libs and installing a new development environment from scratch.
Bundler will install project-specific versions of your gems so that you don't have to manage global dependencies.
In effect, if you install Rails with bundler and you also install it with sudo gem install rails or something like that, you'll have two versions on your computer. By default, calling rails will refer to the global version.
If you call bundle exec rails (or bundle exec <gem_name>), it will call the bundler-specific version.
Ten steps to resolve your issues with Bundler
(optional) Uninstall Ruby. There are many ways to do so, here's one: https://superuser.com/questions/194051/how-to-completely-remove-ruby-ruby-gems-on-mac-os-x-10-6-4
(optional) Use rbenv to install Ruby. Follow instructions here: https://github.com/rbenv/rbenv
Make a repo directory that will house your future Rails app
From the command line:
mkdir repo
cd repo
Install Bundler and create a Gemfile for the directory
From the command line:
gem install bundler
bundle init
Open the repo/Gemfile with your editor, and configure it to instruct Bundler which version of Rails to install
In repo/Gemfile:
source "https://rubygems.org"
gem "rails", "4.2.6"
Install Rails via Bundler
From the command line:
bundle install
Create a new Rails app using Bundler, and cd into it
From the command line:
bundle exec rails new whatevs
cd whatevs
Your Rails app will have a Gemfile by default. Open it and add the gems you wish to use in your app.
In repo/whatevs/Gemfile:
gem 'nokogiri', '1.6.8'
From repo/whatevs/ directory, install your app's Gems via Bundler
From the command line:
bundle install
From repo/whatevs/ directory, generate a controller
From the command line:
bundle exec rails generate controller static_pages home help
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
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
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.