Ruby gem show "Invalid argument" error for almost every command - ruby

I am working through NativeScript's set-up on OS X El Capitan and I am stuck at the point where I am supposed to install xcodeproj and cocoapods. Almost everything that I try to do with gem shows the same error:
$ sudo gem install xcodeproj
ERROR: While executing gem ... (Errno::EINVAL)
Invalid argument
The following commands show the same error, wether I run it with sudo or not:
$ gem update --system
$ gem update
$ gem install whatever
$ gem install cocoapods
I have the following versions:
$ ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
$ gem --version
2.6.7
I've tried some of the help that I've found online, including reinstalling gem and ruby, restarting but nothing has helped.
I guess that I have a configuration problem with Ruby.
Any suggestions on how to troubleshoot this?

I just had a similar issue after updating everything via Homebrew.
I solved the issue by uninstalling Ruby and installing it via rbenv, then reinstalling cocoa pods.
Steps:
Uninstall ruby
brew uninstall ruby
Install rbenv and ruby-build
brew install rbenv ruby-build
You need to add Ruby to your path.
A. If Terminal is your shell.
Add eval "$(rbenv init -)" to ~/.bash_profile
B. Or if you use another shell
You can find the instruction by entering the command rbenv init NAME_OF_YOUR_SHELL.
Install Ruby
rbenv install 2.3.1
Set the Ruby version
rbenv global 2.3.1
rbenv local 2.3.1
Reinstall Cocoapods
gem install cocoapods

Related

Cannot use RSpec (rspec: command not found)

So I installed the newest version of Ruby:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
By following these steps:
brew install ruby
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
I needed to change the Path so that I could use the newest version of Ruby since if not, whenever I did
ruby -v
It would just take into account the default ruby version I had installed in my MAC:
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
Everything works great but I want to install RSpec, so I do:
gem install rspec
This is what I get:
Successfully installed rspec-3.10.0
Parsing documentation for rspec-3.10.0
Done installing documentation for rspec after 0 seconds
1 gem installed
But once I check the version:
rspec --version
This is what I get:
-bash: rspec: command not found
I have uninstalled ruby with brew and installed it again and restarted the terminal but to no avail...Any idea why is this happening? How can I solve it?
Thank you!
It seems that installing Ruby via Home Brew was giving some problems when trying to run RSpec so I uninstalled it and installed it again via RVM. Although, as #Mskha said, Rbenv could also be a possible option.

How to set up Jekyll cleanly on an existing OSX system?

I am an inexperienced Ruby user and I want to start using a Jekyll theme. I am working on OSX El Capitan and there may be old Ruby tools lying around on this machine.
I have downloaded this theme and installed it to a local directory. Next I tried to run bundle and saw this error:
An error occurred while installing nokogiri (1.5.9), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.
Full error output here: http://pastebin.com/mv2r91xU
Next, I tried running gem install nokogiri -v '1.5.9', but I saw this error:
-bash: /usr/local/bin/gem: No such file or directory
I don't know how to install gem, and I suspect I'm not using the "right" Ruby or bundler. Where should these tools be? What do I need to check I've deleted to start cleanly from scratch? (e.g. I tried setting up rbenv, but I think it may have failed because I already had RVM installed)
These are the paths to ruby and bundler:
$ which ruby
/usr/bin/ruby
$ which bundle
/usr/local/bin/bundle
I'd suggest using rbenv to manage your Ruby versions, and ignoring the default system-wide version. You mention you tried, but I think it'd be worth giving it another go.
rbenv is best installed through Homebrew, install it with the following:
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then install rbenv with Homebrew:
$ brew install rbenv ruby-build
You can then set and switch between Ruby versions (giving you clean environments) anytime without changing the default system version:
$ rbenv install 2.3.1
$ rbenv global 2.3.1
$ ruby -v
Once Ruby is sorted, you should be able to install and run the latest Jekyll through the Bundler:
$ gem install jekyll
$ jekyll new my-awesome-site
$ cd my-awesome-site
$ bundle install
$ bundle exec jekyll serve
Running Jekyll through Bundler rather than directly is the new suggested method.

How to get newer version of Ruby into gem environment

I've installed Ruby 2.2.2 with rbenv. However when I run
gem env
it says that I am using 2.0.0. I read on a different question to run
sudo gem install -n /usr/local/bin --no-ri --no-rdoc bundler
rbenv rehash
bundle --path=vendor/bundle
However, when running the last line, I receive the error:
Could not locate Gemfile or .bundle/ directory
How do I get the system to use Ruby 2.2.2?
EDIT:
I printed out the contents of my .bash_profile and it had the following two lines:
export PATH
export PATH="$HOME/.rbenv/bin:$PATH"
Is it bad that there is a blank export PATH? If so, how do I remove it?
If you have Ruby 2.2.2 installed already, you can use renv global
rbenv global 2.2.2
Check out the documentation here.
It turns out RVM was still present in the system. All I had to do was run:
rvmsudo rvm implode

Struggling installing Jekyll on El Capitan

I'm having issues getting Jekyll working on El Capitan. Well, any Gem really. All my Gem installs failed, and I found out it was because of Apple's System Integrity Protection, and the recommended solution is to use ruby versioning tool RBENV.
Installed rbenv and ruby-build using homebrow
Installed Ruby 2.3.0
Set rbenv global to 2.3.0
ran rbenv init and added it to ~/.zshenv so my path now looks like: /usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/thuijls/.rbenv/shims
gem install works fine, I installed jekyll and some other gems. No drama, everything installed to /usr/local/bin/gems.
ran rbenv rehash
Running any of them tho:
/usr/local/bin/jekyll:22:in `load': cannot load such file -- /Library/Ruby/Gems/2.0.0/gems/jekyll-3.0.3/bin/jekyll (LoadError)
from /usr/local/bin/jekyll:22:in `<main>'
They still try to access Apple's standard Ruby in /Library/, which is where none of those Gems are installed.
Any suggestions?
Although I don't use rbenv, try these few steps:
run brew prune to fix the system's symlinks;
fix any other issues indicated by brew doctor;
use .bash_profile in your home folder instead of ~/.zshenv
If it still doesn't work, try using RVM:
install it with an argument to set up your PATH properly with: \curl -sSL https://get.rvm.io | bash -s stable --auto-dotfiles
set RVM to use Homebrew to install any necessary dependencies with rvm autolibs enable && rvm autolibs packages && rvm autolibs homebrew
install ruby-2.3.0: rvm install 2.3.0
go ahead and install any gem on your current gemset

Why do I get "ERROR: While executing gem ... (Gem::FilePermissionError)"?

I uninstalled RVM and re-installed using a single user installation using:
\curl -L https://get.rvm.io | bash -s stable
When I do bundle, it prompts for:
Enter your password to install the bundled RubyGems to your system:
I tried using the answer in "ERROR: While executing gem … (Gem::FilePermissionError)" which did not fix it.
Then, while trying to install the gem manually, I got:
Gem::InstallError: nokogiri requires Ruby version >= 1.9.2.
An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling.
then running gem install nokogiri -v '1.6.0' returned:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.
I checked all the similar posts on SO, but they didn't solve the problem. What am I missing?
I spent a lot of time fixing this issue on my MacBook. The gem update --system does not work for me.
At last, putting the following code in the ~/.zshrc file and create a new zsh session works for me.
export GEM_HOME="$HOME/.gem"
export GEM_PATH="$HOME/.gem"
after you install RVM you still need few more steps:
Load RVM to the current shell:
source ~/.rvm/scripts/rvm
Usually this would not be needed if you close and open your terminal again
Install ruby:
rvm install ruby
Use ruby:
rvm use ruby
The last step is very important as your error message mentioned system ruby not the one controlled by RVM.
Make sure to update your system rubygems with this command : sudo gem update --system --no-user-install.
bundler use it instead your local version and your bundler version could be incompatible with your system rubygems.
It works for me ;)

Resources