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.