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:
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
...