Cocoa pods install inside user directory(without sudo) - ios

I can only access my directory, so I want to install the cocoa pods to the users directory. How can I achieve this?
I follow the below link but is not working.
Sudo-less installation
Please assist me how to achieve this.
I'll be very thankful if any one provide me step by step procedure to achieve this.
What I tried
gem install cocoapods --user-install
Error I'm getting
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:959:in `read': Permission denied - /Library/Ruby/Gems/2.0.0/specifications/terminal-notifier-1.6.0.gemspec (Errno::EACCES)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:959:in `load'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:644:in `block (2 levels) in each_spec'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:643:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:643:in `block in each_spec'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:642:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:642:in `each_spec'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:658:in `each_normal'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:669:in `_all'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/specification.rb:822:in `each'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems.rb:431:in `map'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems.rb:431:in `find_files'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems.rb:942:in `load_plugins'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/gem_runner.rb:73:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/bin/gem:9:in `<main>'
Thanks in advance

I'm posting the steps which worked form me (In case any one need this).
I used Homebrew and bundler
Install homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install brew-gem:
brew install brew-gem
Install bundler:
brew gem install bundler
bundler is a package management tool which provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed.
Then add cocoapod in gemfile (if gemfile is missing then, use bundle init to create gemfile).
Then naviaged to your project directory and execute following command
bundle install --path vendor
The above command will look the gemfile and install the all the gems in the vendor directory.
Now onward prefix the bundle exe to add the cocoapod commands.
i.e
bundle exec pod install
bundle exec pod update

Related

gem install rails -v 4.2.4 Failed to install

I receive the following error message when running this command:
gem install rails -v 4.2.4
This is the error:
/Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/yaml.rb:5:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
/Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': dlopen(/Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/psych.bundle, 9): Library not loaded: /usr/local/opt/libyaml/lib/libyaml-0.2.dylib (LoadError)
Referenced from: /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/psych.bundle
Reason: image not found - /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/psych.bundle
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/psych.rb:7:in `<top (required)>'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/yaml.rb:6:in `<top (required)>'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems.rb:628:in `load_yaml'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/config_file.rb:326:in `load_file'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/config_file.rb:198:in `initialize'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/gem_runner.rb:75:in `new'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/gem_runner.rb:75:in `do_configuration'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/gem_runner.rb:40:in `run'
from /Users/adamgoldberg/.rvm/rubies/ruby-2.3.0/bin/gem:21:in `<main>'
Please Help - this is causing me nightmares
It seems your ruby installation is missing psych (for YAML output).
Install libyaml with Homebrew: http://brew.sh; then try gem install rails -v 4.2.4
$ brew info libyaml
libyaml: stable 0.1.6 (bottled)
YAML Parser
http://pyyaml.org/wiki/LibYAML
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/libyaml.rb
==> Options
--universal
Build a universal binary
$ brew install libyaml
==> Downloading https://homebrew.bintray.com/bottles/libyaml-0.1.6_1.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libyaml-0.1.6_1.el_capitan.bottle.tar.gz
🍺 /usr/local/Cellar/libyaml/0.1.6_1: 8 files, 312.8K
REINSTALL RUBY
If the above solution doesn't work for you, reinstall Ruby from scratch with rvm or rbenv,
1) Try the instructions on this accepted answer: https://stackoverflow.com/a/38194139/1076207
—OR—
2) Remove all rvm files, then reinstall rvm: https://stackoverflow.com/a/38158619/1076207
—OR—
3) Remove all rvm files, then install rbenv: https://stackoverflow.com/a/38194231/1076207
After using one of the three options above, use http://bundler.io to install Rails:
$ mkdir ~/Documents/Repo
$ cd ~/Documents/Repo
$ gem install bundler
[…]
$ bundle init
Writing new Gemfile to /Users/username/Documents/Repo/Gemfile
$ echo "gem 'rails', '4.2.4'" >> Gemfile
$ bundle install
[…]
$ bundle exec rails new project_name
[…]
$ cd project_name
Personally, I recommend 3) switch to rbenv—I did.
The error itself clearly says that you should install libyaml first and then re-install your ruby. You can do it by running following commands.
sudo apt-get install libtool
rvm package install libyaml
rvm reinstall ruby-2.3.0
for more reference please see this answer

Ruby on rails bundle install - json error

I have a lot of difficulties to run Ruby on Rails. Maybe you can tell me where I'm wrong ?
I'm on Linux Mint 17.2, with LAMP local server.
To install Ruby :
$ sudo apt-get install ruby
$ ruby -v
ruby 1.9.3p484
$
I didn't have to install gem, it works as shown here :
$ gem help commands
GEM commands are:
build Build a gem from a gemspec
cert Manage RubyGems certificates and signing settings
(...)
update Update the named gems (or all installed gems) in the local
repository
which Find the location of a library file you can require
For help on a particular command, use 'gem help COMMAND'.
Commands may be abbreviated, so long as they are unambiguous.
e.g. 'gem i rake' is short for 'gem install rake'.
Then I installed rails, I dont remember which of those two ways :
$ sudo gem install rails
or
$ sudo apt-get install ruby-railties-4.0
I dont find how to uninstall, so I can't test other ways to install.
Then, I made an application :
$ rails new (path)/second_app
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/javascripts/application.js
(...)
create vendor/assets/javascripts
create vendor/assets/javascripts/.keep
create vendor/assets/stylesheets
create vendor/assets/stylesheets/.keep
run bundle install
/usr/lib/ruby/1.9.1/rubygems.rb:308:in `bin_path': can't find gem bundler (>= 0) (Gem::GemNotFoundException)
from /var/lib/gems/1.9.1/gems/railties-4.0.2/lib/rails/generators/app_base.rb:268:in `bundle_command'
from /var/lib/gems/1.9.1/gems/railties-4.0.2/lib/rails/generators/app_base.rb:277:in `run_bundle'
from (eval):1:in `run_bundle'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `block in invoke_all'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `each'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `map'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/invocation.rb:133:in `invoke_all'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/group.rb:232:in `dispatch'
from /var/lib/gems/1.9.1/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
from /var/lib/gems/1.9.1/gems/railties-4.0.2/lib/rails/commands/application.rb:43:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /var/lib/gems/1.9.1/gems/railties-4.0.2/lib/rails/cli.rb:15:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /var/lib/gems/1.9.1/gems/railties-4.0.2/bin/rails:9:in `<top (required)>'
from /usr/local/bin/rails:23:in `load'
from /usr/local/bin/rails:23:in `<main>'
It looks like it was a problem running bundle install. According to tutorials, I run the command
$ bundle install
And I got
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.4.2)
Using i18n (0.7.0)
Using minitest (4.7.5)
…
Using jbuilder (1.5.3)
Using jquery-rails (3.1.3)
Installing json (1.8.3)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:1:in `<main>'
Gem files will remain installed in /home/alejandro/.bundler/tmp/9377/gems/json-1.8.3 for inspection.
Results logged to /home/alejandro/.bundler/tmp/9377/gems/json-1.8.3/ext/json/ext/generator/gem_make.out
An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3'` succeeds before bundling.
I tryed to install json in several ways :
$ sudo gem install json -v '1.8.3'
$ sudo apt-get install json -v '1.8.3'
$ sudo gem install json
But it don't work. I tryed to to run de server :
$ rails server
Could not find gem 'rails (= 4.0.2) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
I have tryed to install rvm and rbenv, but nothing works in the way tutorials says it should. My feeling is that I missed something in the begynning, but I dont know what.
Could you please help me ?
Thanks
Alex
You need to update gem lock and all dependency
For that please execute below command,
gem update --system
Now You can install json gem using ,
gem install json
Try above command and let me know if you still face same thing. Above things works fine for me:D

Gem libxml-ruby (1.1.4) installs but fails on runtime

I'm trying to run one quite old Rails application on Mavericks where one of the requirements are:
- Ruby ree-1.8.7-2009.10
- Rails 3.0.0
- libxml-ruby 1.1.4 (that's the latest version compatible with the rest of the gems.
I have latest libxml2 package installed. It's version from Homebrew (2.9.1).
To install this gem I used following command:
$ CC=gcc-4.2 gem install libxml-ruby -v '1.1.4'
Output suggested success:
Building native extensions. This could take a while...
Successfully installed libxml-ruby-1.1.4
1 gem installed
though when I try run some rake task, i.e. creating database
bundle exec rake db:create
I get following error:
$ bundle exec rake db:create [ree-1.8.7-2009.10#mygemset]
rake aborted!
dlsym(0x7ffa2d83bbe0, Init_libxml_ruby): symbol not found - /Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/libxml-ruby-1.1.4/lib/libxml_ruby.bundle
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/libxml-ruby-1.1.4/lib/libxml_ruby.bundle
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:597:in `new_constants_in'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/libxml-ruby-1.1.4/lib/libxml.rb:9
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:597:in `new_constants_in'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
/Users/myuser/Developer/my-project/vendor/private_gems/restful_authentication-1.4.9/lib/sso/sso.rb:3
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:597:in `new_constants_in'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:225:in `load_dependency'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#mygemset/gems/activesupport-3.0.20/lib/active_support/dependencies.rb:242:in `require'
/Users/myuser/Developer/my-project/vendor/private_gems/restful_authentication-1.4.9/lib/restful_sso_authentication.rb:2
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `each'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `each'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `require'
/Users/myuser/.rvm/gems/ree-1.8.7-2009.10#global/gems/bundler-1.5.2/lib/bundler.rb:131:in `require'
/Users/myuser/Developer/my-project/config/application.rb:5
/Users/myuser/Developer/my-project/Rakefile:6:in `require'
/Users/myuser/Developer/my-project/Rakefile:6
(See full trace by running task with --trace)
I have tried numerous approaches that can be found on Internet (the most relevant examples concerned problems with installing Nokogiri and similar errors where listed) and none of them worked.
Here is my way to install Rubies on variety of Mac OSes for long long time. For me, there were any no problems with any library or gem. For example more complex Nokogiri gem builds and works like a charm.
Check XCode version
xcodebuild -version
xcode-select --install
Install Homebrew as per it's documentation
Install prerequisites
brew doctor; # Just do what it wants!
brew update;
brew upgrade; # Watch out! for existing bottles
brew install libtool libxml2 libxslt openssl sqlite libyaml;
brew install autoconf automake apple-gcc42;
brew cleanup; # Watch out! for existing bottles
brew tap homebrew/dupes; # Watch out! for existing bottles
Install RVM
curl -L https://get.rvm.io | bash -s stable # Latest stable
rvm get latest
rvm reload # :)
rvm autolibs enable
rvm requirements
Install Ruby
rvm install 2.1 --disable-binary
Probably a previous version break the native loading or your libxml2 is too recent and don't fit the gem implementation.
first uninstall all previous gems (gemset, system)
then reinstall the gem
https://gist.github.com/unixcharles/1226596 ?

rails cannot load such file -- mysql2/mysql2 (LoadError)

I am newbie to ruby on rails i could not find the solution for this error:
rails s
/usr/local/share/gems/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `require': cannot load such file -- mysql2/mysql2 (LoadError)
from /usr/local/share/gems/gems/mysql2-0.3.13/lib/mysql2.rb:8:in `<top (required)>'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /usr/local/share/gems/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
from /home/Harish/Documents/simple_cms/config/application.rb:7:in `<top (required)>'
from /usr/local/share/gems/gems/railties-4.0.0/lib/rails/commands.rb:76:in `require'
from /usr/local/share/gems/gems/railties-4.0.0/lib/rails/commands.rb:76:in `block in <top (required)>'
from /usr/local/share/gems/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from /usr/local/share/gems/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
gem uninstall mysql2
gem install mysql2 --platform=ruby
delete the mysql2 gem directory in your rails specific bundle directory and copy paste this newly install mysql2 gem
For Rails 3.2.17 and Ruby 1.9.3-p448 and mysql2 0.3.11, running bundle update mysql2 updated to 0.3.15 and got rid of the error for me.
Ya, It's happening with new version(0.3.13) of mysql2 gem with rails 4.0.0. Deleting the bundle folder under vendor directory, and rerunning bundle install, update fixed this issue for me
cd {Your_RailsApp_Root}/vendor/
rm -rf bundle/
cd {Your_RailsApp_Root}
bundle install
bundle update
Do you have the mysql2 gem installed? Check that your gemfile has gem "mysql2" and then run bundle install from the root of your rails app. Also, ensure that you mysql downloaded in your development environment.
just downgrade the mysql2 version. In my case, I used '0.2.6' version and it worked for me.
gem 'mysql2', '0.2.6'
with ruby version 2.0.0 and gem version 1.8.25
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
from
https://gorails.com/setup/osx/10.14-mojave
I battled this for a day when running into it while trying to run bundle exec rake db:migrate after successfully bundle installing my project gems.
For me, mysql2 was trying to load a configuration file that didn't exist. I had already brew installed mysql on my system, and what mysql2 was looking for existed already in the mysql installation. I ran
gem install mysql2 -v 0.5.3 -- --with-mysql-config=/usr/local/Cellar/mysql#5.6/5.6.42/bin/mysql_config --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
to point mysql2 to the correct configuration.
NOTE the version you have of mysql may be different and the version of the gem you want may also be different.
ALSO NOTE: the gem install path may be different than your bundle install path. You can also the gem to your bundle directory with
gem install --install-dir /path/to/bundle/directory
OR you can set gem options with your bundle build configuration:
bundle config --local build.mysql2 --with-mysql-config="/usr/local/Cellar/mysql#5.6/5.6.42/bin/mysql_config" --with-ldflags=-"L/usr/local/opt/openssl/lib" --with-cppflags=-"I/usr/local/opt/openssl/include"
Apple silicon M1:
gem install mysql2 -v '0.5' -- --with-opt-dir=$(brew --prefix openssl)
It work for me.
gem uninstall mysql2
sudo gem install mysql2
bundle
this solved my error:
[root#localhost cms]# su Harish
[Harish#localhost cms]$ bundle install
[Harish#localhost cms]$ rails s

Getting nokogiri to use a newer version of libxml2

I've been trying to get Nokogiri installed on my computer (Mountain Lion) to use with rspec and capybara, but for the life of me, I can't get it to run properly.
From what I can tell, the issue is with nokogiri using the wrong version of libxml2. I've so far tried uninstalling and reinstalling libxml2 using Homebrew (making sure it's the most recent one), uninstalling and reinstalling nokogiri using bundle, and specifying the exact path to the libxml2 files that Homebrew installed when installing the nokogiri gem. My most recent install instructions looked like this
sudo gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28
where all of those locations do correctly correspond to the locations where the tools are installed. However, upon running bundle exec rspec spec/requests/static_pages.rb, I still get this output:
/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `require': dlopen(/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle, 9): Library not loaded: /usr/local/lib/libxml2.2.dylib (LoadError)
Referenced from: /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle
Reason: Incompatible library version: nokogiri.bundle requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0 - /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle
from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `<top (required)>'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286#global/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
from /Users/alex/Sites/harbingernews/config/application.rb:7:in `<top (required)>'
from /Users/alex/Sites/harbingernews/config/environment.rb:2:in `require'
from /Users/alex/Sites/harbingernews/config/environment.rb:2:in `<top (required)>'
from /Users/alex/Sites/harbingernews/spec/spec_helper.rb:3:in `require'
from /Users/alex/Sites/harbingernews/spec/spec_helper.rb:3:in `<top (required)>'
from /Users/alex/Sites/harbingernews/spec/requests/static_pages_spec.rb:1:in `require'
from /Users/alex/Sites/harbingernews/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run'
from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun'
I've tried all the steps that I've found online (most reference building and loading different versions of libxml2, like this one, but have had no success yet. My Gemfile and Gemfile.lock can be found here. If anyone can help me out at all, I would really appreciate it. I haven't been able to find any other cases online with this problem.
In Mavericks, installing the libraries with brew and setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1 before installing the gem did the trick for me.
Summarising:
If previously installed, uninstall the gem:
$ gem uninstall nokogiri
Use Homebrew to install libxml2, libxslt and libiconv:
$ brew install libxml2 libxslt libiconv
Install the gem specifying the paths to the libraries to be linked against:
$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
This helps me to update libxml and install nokogiri correctly...
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew link --force libxml2
brew install libxslt
brew link --force libxslt
bundle config build.nokogiri -- --with-xml2-dir=/usr
--with-xslt-dir=/opt/local --with-iconv-dir=/opt/local
bundle install
Here is the source: http://www.kormoc.com/2013/12/22/nokogiri-libxml2/
Hope this helps somebody...
Just to make it clear, Phrogz's comment helped me out quite a bit. I followed the instructions that he linked to, the What to do if libxml2 is being a jerk? page on Nokogiri's Github page. I ended up using Macports instead of Homebrew, and I'm not sure if that's what made the difference (I had tried many of those steps already) but one way or another, it seems to be working alright now.
Googled this question after upgrading OsX when I had problem:
require': dlopen(/Users/tomi/.rvm/gems/ruby-2.1.1#my-gemset/extensions/x86_64-darwin-12/2.1.0-static/nokogiri-1.5.10/nokogiri/nokogiri.bundle, 9): Library not loaded: /usr/local/opt/libxml2/lib/libxml2.2.dylib (LoadError)
and this worked for me
brew uninstall libxml2 libxslt libiconv
brew install libxml2 libxslt libiconv

Resources