While executing gem, unknown command

2019-01-24 07:00发布

问题:

Whenever I enter a gem command, such as

gem "tilt"

or

gem "mysql"

I get this error:

While executing gem ... <RuntimeError>
Unknown command tilt

When I run gem list, both tilt and mysql show up on the list, so they are installed. In fact, I get this error with every item on the list. What could be causing this?

回答1:

gem isn't lying to you, they aren't valid gem commands.

Perhaps you're confusing the command line with Bundler? For example, adding

gem "tilt"

to a Gemfile and running bundle install will install tilt. But Bundler uses its own syntax, and isn't a shell script. To install tilt using the gem binary directly you'd have to do:

gem install tilt

Running gem help will give you a list of gem's command line arguments.



回答2:

You're using the Gemfile syntax and you should be using the commandline syntax. Give this a try:

gem install mysql2 -v 0.2.7


回答3:

Make sure your syntax is correct for more guidelines you can type

gem help

To see the acceptable syntax for ruby,

If you get this error "You don't have write permissions for the /Library"

You can always add sudo to elevate privileges.

eg. sudo gem install <gemname>

Using sudo before your code and that will give you administrative access (after you type your computer password).

After that you may have to run bundle install to install the gem.