While executing gem, unknown command - ruby

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?

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.

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

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.

Related

gem install pry FilePermissionError

When I tried to install pry on terminal, it keeps telling me
$ gem install pry
While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0
directory.
I've tried to update gem, using homebrew to install ruby. but still get the same error.
Common Practices when something says what you don't have permission to perform an action:
Try to execute the command with sudo prefix (sudo gem install pry).
Execute the command as root (Not recommended due to potential issues).

Gem install error: 'Please specify at least one gem name'

When I run 'gem install bundler' for example, it works fine if I am running ruby version 1.9.3, but when running ruby 2.1.2, it seems not to see the 'bundler' arg and gives me
ERROR: While executing gem ... (Gem::CommandLineError)
Please specify at least one gem name (e.g. gem build GEMNAME)
I see this on two different systems running rbenv.
Here is the last part of the output when running with RBENV_DEBUG=1:
+ [rbenv-exec:45] export PATH=/home/ded/.rbenv/versions/2.1.2/bin:/home/ded/.rbenv /libexec:/home/ded/.rbenv/plugins/bundler/bin:/home/ded/.rbenv/plugins/ruby-build/bin:.bundle/bin:/home/ded/.rbenv/shims:/home/ded/.rbenv/bin:/home/ded/.cabal/bin:/home/ded/.emacs/ded/lisp/ecukes:/home/ded/local/node/bin:/home/ded/j64-701/bin:/home/ded/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/plan9/bin
+ [rbenv-exec:45] PATH=/home/ded/.rbenv/versions/2.1.2/bin:/home/ded/.rbenv/libexec:/home/ded/.rbenv/plugins/bundler/bin:/home/ded/.rbenv/plugins/ruby-build/bin:.bundle/bin:/home/ded/.rbenv/shims:/home/ded/.rbenv/bin:/home/ded/.cabal/bin:/home/ded/.emacs/ded/lisp/ecukes:/home/ded/local/node/bin:/home/ded/j64-701/bin:/home/ded/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/plan9/bin
+ [rbenv-exec:47] exec -a gem /home/ded/.rbenv/versions/2.1.2/bin/gem install bundler
ERROR: While executing gem ... (Gem::CommandLineError)
Please specify at least one gem name (e.g. gem build GEMNAME)
Any suggestions what could be going wrong?
Changed my ~/.gemrc from
gem: --document
to
gem: --ri-document
and that solved the problem. Not sure why it was not a problem with ruby 1.9.3.
Try to uninstall all
** $ sudo gem uninstall --all**
2.try to install ruby
** $ sudo gem install ruby**
then install cocoapods then perfectly working
$ sudo gem install cocoapods

OS ruby labs/ PATH installation problems

I am supposed to install ruby labs on my computer and the instructions given to me are found here: http://ix.cs.uoregon.edu/~conery/eic/software.html
However, I'm facing problems downloading the ruby labs gem. The command given was:
gem install --user-install rubylabs -n .
I keep receiving these errors:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Users/Admin/.gem/ruby/1.8 directory.
I then did sudo gem install --user-install rubylabs -n .
But i got this error instead:
Successfully installed rubylabs-0.9.8
Installing ri documentation for rubylabs-0.9.8
/Users/Admin/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/rdoc/rdoc.rb:280: warning: conflicting chdir during another chdir block
/Users/Admin/.rvm/rubies/ruby-1.8.7-p371/lib/ruby/1.8/rdoc/rdoc.rb:287: warning: conflicting chdir during another chdir block
Furthermore, after proceeding on with ruby lab-setup.rb, when I type irb, i receive this error as well: no such file to load -- rubylabs
===============================
Apparently it was my RVM that was causing the problem and deleting it solved the above problem. However, I would like to understand why RVM cause those issues.
Could someone please help? I'm at my wits end.
Thanks
I just had this issue as well:
no such file to load -- rubylabs
ruby lab-setup.rb basically adds lines to require rubygems and rubylabs on each new IRB session. The above no such file to load basically meant that rubylabs is not installed locally in rvm. A gem list command would reveal something like the following:
MBA:~ user$ gem list
*** LOCAL GEMS ***
gem-wrappers (1.2.4)
rvm (1.11.3.9)
I am new to Ruby as well... So what I did was basically just run the following command to install rubylabs:
gem install rubylabs -n .
A gem list would reveal it as installed:
*** LOCAL GEMS ***
gem-wrappers (1.2.4)
rake (10.1.1)
rubygems-test (0.4.3)
rubylabs (0.9.8)
rvm (1.11.3.9)
IRB will now run normally.

Can't install JSON gem

I need to install json because I get this error:
Could not find json-1.4.6 in any of the sources
I ran gem install json and bundle install but I was only able to install json-1.5.1 when I need json-1.4.6
I have gem 'json', '1.4.6' in my gemfile, so I'm not sure what's going on...
UPDATE
I get this error:
Installing json (1.4.6) /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/fileutils.rb:1216:in `chmod': Operation not permitted - /Library/Ruby/Gems/1.8/gems/json-1.4.6/CHANGES (Errno::EPERM)
After checking logs by running $ heroku logs
I found "An error occurred while installing json (1.4.6), and Bundler cannot continue.
Make sure that gem install json -v '1.4.6' succeeds before bundling."
I then removed 2 json entries from the Gemfile.lock and had no further issues.
Why did you run gem install json at all? Bundler takes care of that for you and will ensure that the correct version of each gem is installed (since sometimes dependencies require an older version). Run
gem uninstall json
bundle install
Also ensure you have source 'https://rubygems.org' at the top of your Gemfile.
As for the permissions info, you may have to run gem and bundle commands with sudo.
By the way, I highly recommend taking a look at and using RVM, particularly the gemsets feature. It will make your life infinitely better when developing Ruby apps. If you decide to do so, I'd also suggest trashing all the gems you've install using the system Ruby by running sudo rm -rf /Library/Ruby/Gems/1.8/. It's also important that when using RVM you don't have to use sudo when running gem (or bundle), which is not only safer but less typing too.
Please update your rubygems by executing the following command..
gem update --system
may be it will solve the problem. After updating your gem. Then run the following command to install json
gem install json
Now you can get json gem installed in your system.
Try:
$ sudo apt-get install ruby1.8-dev
If you're using rbenv, try rbenv rehash
I had this problem when trying to build a website with Jekyll.
Turned out I hadn't followed all the instructions at https://jekyllrb.com/docs/installation/ubuntu/
I don't know if it was the missing packages or commands into ~/.bashrc but it fixed the problem in two instances of Ubuntu in WSL
Remove the json entries from the Gemfile.lock file and try to re run bundle install..

How to force gem install to download the docs file as well?

I've setup the following in my ~/.gemrc file
gem: --no-ri --no-rdoc
so that when I do gem install some_gem, the rdocs won't get installed to not pile up my disk.
But for some gem, I'ld like to install the rdocs as well. So i tried,
gem install some_gem --rdoc --ri
the docs doesn't get downloaded. How can I force the gem install to download rdocs as well for some gem if I wnat to??
You can create a second config file called ~/.gemrc_withdoc or something similar and include the commands to install with documentation then try the following comand
gem install some_gem --config-file=~/.gemrc_withdoc
You may even be able to get away with not creating a confile file at all and running
gem install some_gem --config-file=/dev/null
This should work as expected because gem will only use one config-file, either the one specified on the command line or ~/.gemrc. It will never use both
--rdoc and --ri are indeed the correct options, according to gem help install. If it doesn't work as expected, I assume that you have to edit your ~/.gemrc every time you want to install rdocs and ri.

Resources