Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know that a gem is compatible with a version of rails?

I'm just getting started with ruby on rails and as I follow the tutorial, there isn't an explanation of how certain gems were gathered and placed in the Gemfile. I've just been copying and pasting them and putting them in my Gemfile and running bundle install.

How does one go about downloading specific versions of gems, and their dependencies as well as making sure that they are compatible with the version of rails I'm using?

like image 380
Nehemiah Mekonnen Avatar asked Apr 22 '17 02:04

Nehemiah Mekonnen


People also ask

How do I check my gem version?

To check if a specific version is installed, just add --version , e.g.: gem list -i compass --version 0.12.

How do I specify a gem version?

There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .

How do I check Ruby on Rails version?

Step 1: Check Ruby VersionOpen the command prompt and type ruby -v. If Ruby responds, and if it shows a version number at or above 2.2. 2, then type gem --version. If you don't get an error, skip Install Ruby step.

Is Ruby on Rails a gem?

Some developers prefer using their code for the purpose; others prefer using Ruby gems for authentication. DEVISE gem ruby on rails turns out one of the best rails gems 2021. It makes work effective and easy.


2 Answers

Bundler figures out which versions to install depending on your current Rails version if you don't specify the Gem version. Usually Bundler will warn you also when it can't install a version you specified.

gem 'gemname'

This installs whatever version is compatible with your Rails version.

gem 'gemname', '1.5'

This installs version 1.5 only if it supports your current Rails version.

gem 'gemname',  '>=1.0'

This installs version 1.0 or greater if available and compatible.

If you want to install a specific version (2.2) but you know that version 3.0 will break your code (some gems do that like Mailchimp gem) you can specify a minimum version and maximum version:

gem 'gemname', '>= 2.2.0', '< 3.0'

Since it is more or less common there is a shortcut for this:

gem 'gemname', '~> 2.2'

The "~>" will match any version smaller than 3.0. It tells bundler to install only 2.X never reaching 3.0.

Every gem you want to install will tell you which version is compatible with your Rails version. Usually it will say the minimum version number. For example the boostrap gem:

https://rubygems.org/gems/bootstrap/versions/4.0.0.alpha3.1

If you look at the site, it tells you the dependencies. It doesn't mention a minimum Rails version so you can install always the latest version:

RUNTIME DEPENDENCIES (2):
autoprefixer-rails >= 6.0.3
sass >= 3.4.19
DEVELOPMENT DEPENDENCIES (13):
actionpack >= 4.1.5
activesupport >= 4.1.5
capybara >= 2.6.0
compass ~> 1.0.3
jquery-rails >= 3.1.0
json >= 1.8.1
minitest ~> 5.8.0
minitest-reporters ~> 1.0.5
poltergeist >= 0
slim-rails >= 0
sprockets-rails >= 2.3.2
term-ansicolor >= 0
uglifier >= 0

If it specifies a Rails version under dependencies like this:

rails >= 4

It means that you need at least Rails 4.0.

like image 165
Alexander Luna Avatar answered Oct 27 '22 11:10

Alexander Luna


For rails 4 and 5 you can check here. If gem ready or not.

Rails automatically install best suited newest version of gem when you run bundle install if you write gem 'gemname'. Specifying a gem version is mention in other answers.

If a specific version of ruby or rails or any dependency is required in a gem. Then it is specified in gemspec file of gem and Gemfile for that gem.

You can cross-check in gemspec or Gemfile of gem also if something break while bundle install.

like image 28
Dipak Gupta Avatar answered Oct 27 '22 12:10

Dipak Gupta