17

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?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
nullnullnull
  • 8,039
  • 12
  • 55
  • 107

3 Answers3

34

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.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
  • The reason I'm asking is because I'm trying to set mysql to a specific version using the command: gem 'mysql2', '0.2.7'. Unfortunately, when I use this command, I get the same error. Any idea why? – nullnullnull Jun 02 '12 at 16:11
  • Because it's not a valid command as I said. If you read the help documents for `gem` as in my question, as well as `gem help install` for those specific to installing, you'll find the correct arguments for installing a specific version: `gem install mysql2 --version 0.2.7`. – Andrew Marshall Jun 02 '12 at 19:05
  • Thanks for the tip, Andrew. I got the original command from another stackoverflow page and I couldn't figure out why it wasn't working on my system. I still don't know, but your command does work. Perhaps it has something to do with OS? – nullnullnull Jun 02 '12 at 20:34
  • No. As I explained in my answer what you were trying to run is meant to go in a Gemfile used by Bundler. – Andrew Marshall Jun 02 '12 at 20:46
  • Just figured out why. The command "gem 'mysql2', '0.2.7'" is meant for the file Gemfile, not for the command line. For the command line, use Andrew's suggestion: "gem install mysql2 --version 0.2.7" – nullnullnull Jun 02 '12 at 20:49
5

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
David Underwood
  • 4,908
  • 1
  • 19
  • 25
1

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.

mattdonders
  • 1,328
  • 1
  • 19
  • 42