Two pits using Ruby Gem under Mac OS X

Keywords: Ruby sudo brew JSON

Original link

Recently, I need to install two things on my mbp with gem, and then I flatten two pits. Make a note of this as a record of the same problems I will encounter in the future.

The first is the Connection Research problem. The symptoms are simple. With gem install, the effect is as follows:

gem install xxx
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org/quick/Marshal.4.8/xxx.gemspec.rz)

The reason is simple. In China, api.rubygems.org is walled, and there is no idea what kind of resentment it is.

The simplest way is to use Taobao mirror.

Taobao Mirror Address is: https://ruby.taobao.org/

The instructions on the front page of Taobao Mirror are very detailed.

If you install it manually with gem, you can do it with the following commands:

$ gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
$ gem sources -l

*** CURRENT SOURCES ***

https://ruby.taobao.org
# Make sure that only ruby.taobao.org is available
$ gem install xxx

It actually modifies your ~/. gemrc file.

If you use bundle s, you can use commands

$ bundle config mirror.https://rubygems.org https://ruby.taobao.org

Under OS X, if you continue gem install, you will easily encounter the following errors

$ gem install xxx
1 gem installed
$ gem install xxx
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

The reason is literally that gem is going to write files to a magical directory, but you don't have enough permissions. Because you're using ruby from Apple's home, trying to stuff things into Apple's own library, which is the default location for root.

There are two bad ways to solve this problem. One is to add sudo before. At this point, remember to replace the source with sudo first. The other is to modify the directory / Library/Ruby/Gems/2.0.0 for users, namely

sudo chown -R your_name:your_name /Library/Ruby/Gems/2.0.0

But my personal best advice is to install a ruby in homebrew, so that local belongs to local, system belongs to system. It's not big anyway.

brew install ruby

Then gem.

$ gem install tmbundle-manager
Fetching: thor-0.19.1.gem (100%)
Successfully installed thor-0.19.1
Fetching: tmbundle-manager-0.1.2.gem (100%)
Successfully installed tmbundle-manager-0.1.2
Parsing documentation for thor-0.19.1
Installing ri documentation for thor-0.19.1
Parsing documentation for tmbundle-manager-0.1.2
Installing ri documentation for tmbundle-manager-0.1.2
Done installing documentation for thor, tmbundle-manager after 1 seconds
2 gems installed

By default, brew's various gems will be loaded at / usr/local/lib/ruby/gems/2.3.0. 2.3.0 is the version number, maybe somewhere else. It's not the original / Library/Ruby/Gems/2.0.0 location.

After we checked gem, we found that the two libraries were completely used for both the system and the system. Very good.

$ gem list --local

*** LOCAL GEMS ***

bigdecimal (1.2.8)
did_you_mean (1.0.0)
io-console (0.4.5)
json (1.8.3)
minitest (5.8.3)
net-telnet (0.1.1)
power_assert (0.2.6)
psych (2.0.17)
rake (10.4.2)
rdoc (4.2.1)
test-unit (3.1.5)
thor (0.19.1)
tmbundle-manager (0.1.2)

$ /usr/bin/gem list --local

*** LOCAL GEMS ***

activesupport (3.2.19)
bigdecimal (1.2.0)
CFPropertyList (2.2.8)
colored (1.2)
i18n (0.6.11)
io-console (0.4.2)
json (1.7.7)
libxml-ruby (2.6.0)
minitest (4.3.2)
multi_json (1.10.1)
nokogiri (1.5.6)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
rubygems-update (2.4.2)
sqlite3 (1.3.7)
test-unit (2.0.0.0)
xcodeproj (0.19.4)

Posted by mikkex on Mon, 10 Dec 2018 04:42:05 -0800