Usage of GEM Package Manager in Ruby and managing multiple versions of Gem_ruby topics with bundler

Source: Internet
Author: User
Tags mkdir versions


Gem Common commands


gem -v # View the version of RubyGems software
gem help #Show RubyGem usage help
gem help example #List some usage examples of RubyGem commands
gem install [gemname] # Install the specified gem package. The program first finds the gem package from the local machine and installs it. If it is not available locally, it installs it from a remote gem.
gem install -l [gemname] # Install gem packages only from this machine
gem install -r [gemname] # only install gem packages from remote
gem install [gemname] --version = [ver] # Install gem packages of specified version
gem uninstall [gemname] # delete the specified gem package, note that this command will delete all installed versions
gem uninstall [gemname] --version = [ver] # delete a specific version of gem
gem update --system # Update the RubyGems software itself
gem update [gemname] #Update all | Specify the installed gem package
gem list # View all gem packages installed on the machine #Show RubyGem help  
Replace Taobao Mirror
due to the domestic network reason (you know), the rubygems.org stored on the Amazon S3 resource file intermittent connection failed. Here to replace the default mirror image for Taobao.
Gem sources--remove https://rubygems.org/
gem sources-a https://ruby.taobao.org/
gem sources-l
* * * Current SOURCES * * *
https://ruby.taobao.org
# Please make sure only ruby.taobao.org


Managing multiple versions of gems with Bundler
with RBENV to manage multiple versions of the Ruby environment, we also need a tool to manage multiple versions of gems (such as rails), which is bundler, the project background is not in detail, need to be understood directly to the official website, here only a few practical use experience
Installation:


Gem Install Bundler


Use:


mkdir App1; CD App1;
echo "Source ' https://ruby.taobao.org/'" > Gemfile
echo "Gem ' rails, ' 4.1.0 '" >> gemfile
Bundle Install


The above code installs the Rails 4.1.0 under App1, uses bundle EXEC rails-v to view the rails version that is used under the current directory, and the display content should be rails 4.1.0, also at this time through bundle exec rails new. --force overwrite the original gemfile, this time the version of the rails used by the app is 4.1.0


mkdir app2; CD app2;
echo "Source ' https://ruby.taobao.org/'" > Gemfile
echo "Gem ' rails, ' 3.2.13 '" >> gemfile
Bundle Install


The code above creates a second App2 folder and installs rails via bundler 3.2.13 also through bundle exec rails new. --force can generate applications based on Rails version 3.2.13
With the above two versions installed, you can see from the Gem list--local that rails has two versions, shown as Rails (4.1.0, 3.2.13), and bundler intelligently judge the rails version of each project to ensure that the application runs correctly, But the premise is to execute the original command by using the bundle EXEC command, for example:


Bundle EXEC Rails s
bundle exec rake db:create
...




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.