Answer can be found by typing
sudo gem environment
then
gem environment
and comparing the results. ( gem env is a short version of the command)
Ruby gems are installed locally in directory under specific ruby version, which is also installed in user specific folder (not sure bout MAC situation, but that's the case on my Ubuntu).
Please see the difference on my machine (I am using rvm - ruby version manager):
with sudo - INSTALLATION DIRECTORY: /var/lib/gems/2.7.0
without sudo - INSTALLATION DIRECTORY: /home/le-hu/.rvm/gems/ruby-2.7.2
Using sudo in this case causes the gem to install under root user, not your regular user profile, this leads into gem missing while trying to invoke the gem script being logged in as not-root user.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.