I'm using Postgres.app on OS X (10.8.3). I have modified my PATH so that the bin folder for the app is before all others.
Rammy:~ phrogz$ which pg_config
/Applications/Postgres.app/Contents/MacOS/bin/pg_config
I have rvm installed and can install the pg gem without error, but when I go to require it I get an error:
Rammy:~ phrogz$ gem -v
1.8.25
Rammy:~ phrogz$ gem install pg
Fetching: pg-0.15.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed pg-0.15.1
1 gem installed
Rammy:~ phrogz$ ruby -v -e "require 'pg'"
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0]
/Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': dlopen(/Users/phrogz/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.1/lib/pg_ext.bundle, 9): Library not loaded: #executable_path/../lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /Applications/Postgres.app/Contents/MacOS/lib/libpq.dylib
Reason: image not found - /Users/phrogz/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.1/lib/pg_ext.bundle
from /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /Users/phrogz/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.15.1/lib/pg.rb:4:in `<top (required)>'
from /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require'
from /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require'
from /Users/phrogz/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
from -e:1:in `<main>'
What do I need to do to get the pg gem properly installed?
Edit: Even though this answer currently has more votes than the accepted answer, the accepted answer is far simpler and cleaner.
Remove the Postgres.app binaries from the path when installing the pg gem, and instead use the postgres install built into OS X to configure the gem. The pg library will still correctly connect to the Postgres.app server later on.
Rammy:~ phrogz$ gem uninstall pg
Successfully uninstalled pg-0.15.1
# Modify PATH to remove /Applications/Postgres.app/Contents/MacOS/bin
Rammy:~ phrogz$ gem install pg
Fetching: pg-0.15.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed pg-0.15.1
1 gem installed
Rammy:~ phrogz$ ruby -v -e "require 'pg'"
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.3.0]
I found a solution that works for me and requires minimal hacking/configuring. You only need to do this once and it will work for every bundle install. Add the following to your .bash_profile, .bash_rc, or equivalent:
export DYLD_FALLBACK_LIBRARY_PATH=/Applications/Postgres.app/Contents/MacOS/lib:$DYLD_LIBRARY_PATH
(Assuming you installed Postgres.app in the default location). Then restart your terminal session and try again.
Exporting to DYLD_LIBRARY_PATH directly can cause serious problems with other apps that depend on it, but using the fallback path avoids these problems.
See also:
https://github.com/PostgresApp/PostgresApp/issues/109#issuecomment-18387546
Postgres.app upgrade, now Rails app won't start
EDIT: It seems that setting DYLD_FALLBACK_LIBRARY_PATH causes an error when you try to run psql. To fix this, you can add the following two lines to your .bash_profile:
alias psql="(. ~/.bash_profile; unset DYLD_FALLBACK_LIBRARY_PATH; psql)";
This is assuming that you're using bash and that your .bash_profile is located in your home directory. If that's not the case (or if you're using a .bashrc or other environment setup instead of .bash_profile) change the ~/.bash_profile part of the command to the path to your environment setup script.
The aliased commands basically start a subshell which does not effect your current bash environment. So when it unsets the DYLD_FALLBACK_LIBRARY_PATH variable, it's only temporary. After you exit psql the environment variable will be set again so that rails functions properly.
This worked for me:
sudo env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-config=/Applications/Postgres93.app/Contents/MacOS/bin/pg_config
Just double check that the /Applications/Postgres93.app.. path exists for you.
The problem is in the linking of the gem to the Postgres.app.
If you link it to the postgres version that ships with osx
Here's a small script:
if using rvm with project gemsets: change into your project
run the following commands:
gem uninstall pg
PATH=${PATH/'Postgres.app'/'WRONGFOLDER.app'}
gem install pg
PATH=${PATH/'WRONGFOLDER.app'/'Postgres.app'}
Now everthing should be fine
Related
So, it seems like ruby isn't able to find gems that are installed? The error:
/Users/userName/.rbenv/versions/2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in
`require': cannot load such file -- activesupport (LoadError)
from /Users/userName/.rbenv/versions/2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in
`require'
from test.rb:3:in `<main>'
I had ruby installed via RVM and brew on my Mac (El Capitan). I don't remember what I had done when I started getting this error when trying to run my ruby program. At the top of my program I have require 'json' and require 'rest-client', and require 'activesupport' Nothing abnormal there.
After a lot of googling, I ended up doing rvm implode and removing the .rvm files from my computer to completely uninstall rvm. I then tried installing ruby via brew, but was getting the same error. I then uninstalled the the brew version of ruby, and installed with rbenv. Still got the same error, but this time with the rbenv path to the kernal_require.rb file instead of the brew or rvm paths that it had showed before.
So something tells me that this is not something to do with rvm or brew or rbenv because I was getting the same error with the versions of ruby I tried for each one. The gems are installed. Why isn't it able to load them? Uninstalling and reinstalling the gems didn't help. I had to reinstall them anyway every time I uninstalled and reinstalled ruby.
gem env home returns this:
/Users/userName/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0
brew config returns this for ruby:
Ruby: /Users/userName/.rbenv/shims/ruby => /Users/userName/.rbenv/versions/2.3.0/bin/ruby
I have these included in my PATH:
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
ruby -v returns this:
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
I've checked for spaces in the file path, I've tried installing bundler and installing gems that way, but I'm still getting the same issue. What else can I look at to solve this problem?
You use
gem 'activerecord'
in the gemfile.
require 'active_support/all'
is used in the program.
It's slightly annoying when gems do this, but you can't always assume the files you require have the same name as in the Gemfile.
I installed CocoaPods and it says Successfully installed cocoapods-0.33.1, but whatever I would try to do with pod command, like pod install, I get the following console output:
Max$ pod install
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin14/rbconfig.rb:213: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- xcodeproj/prebuilt/universal.x86_64-darwin14-2.0.0/xcodeproj_ext (LoadError)
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 /Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.17.0/lib/xcodeproj/ext.rb:6:in `rescue in <top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.17.0/lib/xcodeproj/ext.rb:3: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 /Library/Ruby/Gems/2.0.0/gems/xcodeproj-0.17.0/lib/xcodeproj.rb:30: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 /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/lib/cocoapods.rb:2: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 /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.33.1/bin/pod:32:in `<top (required)>'
from /usr/bin/pod:23:in `load'
from /usr/bin/pod:23:in `<main>'
I am using Mac OS 10.10 (Yosemite beta version) and Xcode 6.0 beta2, but I think back when I used Mavericks and Xcode 5.1.1 I had the same problem.
I finally solved my problem.
Short answer:
I had to install ruby 2.1.2, then reinstall cocoapods and everything worked.
Long answer:
Resolve all warnings from brew doctor;
remove unused libraries;
remove MacPorts;
resolve additional warnings which I already do not remember;
I might even reinstalled brew.
Install rvm;
Install & use ruby 2.1.2 using rvm;
rvm requirements complains about many missing packages, install them;
among them, there is gcc46, which I was unable to install. After Xcode 4.2 or something, command line tools come without gcc. So if rvm requirements does not find one, it suggests gcc46. But the point is, installing brew install apple-gcc42 solves the problem. rvm requirements stops complaining and you can install ruby 2.1.2:
rvm install 2.1.2;
rvm use 2.1.2;
Install cocoapods, as suggested in #Varsha Vijayvargiya's answer.
I might forgot something, so if you have any questions - ask. Here are some links which helped me:
update mac osx to 10.10 and pod cannot work;
Installing Ruby 2.0.0 with RVM and Homebrew on Mac OS X 10.8 Mountain Lion;
Homebrew GCC won't install on OS X 10.10 Yosemite with Xcode 6;
Installing gcc on Mavericks.
-- Open Xcode 6
-- Open Preferences
-- click on Locations tab
-- Change the Command Line Tools version to Xcode 6.0
-- Uninstall cocoapods
$ sudo gem uninstall cocoapods
-- Install xcodeproj
$ sudo gem install xcodeproj
-- Install cocoapods
$ sudo gem install cocoapods
-- Run pod.
You most probably missed a step, but it's not your fault.
sudo gem install cocoapods
pod setup <–- this is not specified by the doc even though it's vital
pod install
See https://github.com/CocoaPods/CocoaPods/issues/2219
Or check that if you have multi ruby versions in your system:rbenv versions, and try rbenv global 1.9.x to change your ruby version for installing.
First warning says that you've insecure permissions for your bin directory:
local:Documents liuxiaojun$ gem update --system
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin14/rbconfig.rb:213: warning: Insecure world writable dir /usr/bin in PATH, mode 040777
Updating rubygems-update
Successfully installed rubygems-update-2.4.3
Parsing documentation for rubygems-update-2.4.3
Installing RubyGems 2.4.3
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin14/rbconfig.rb:213: warning: Insecure world writable dir /usr/bin in PATH, mode 040777
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin14/rbconfig.rb:213: warning: Insecure world writable dir /usr/bin in PATH, mode 040777
ERROR: While executing gem ... (Errno::EACCES)
Permission denied - /Library/Ruby/Site/2.0.0/gauntlet_rubygems.rb
==========
brew install ruby
OK
First warning says that you've insecure permissions for your bin directory:
warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
See: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
You can fix it via (you need root credentials):
sudo chmod go-w /usr/local/bin
The error 'require': cannot load such file indicates that you some missing or broken gem package. You can probably fix it by re-installing cocoapods:
gem uninstall cocoapods # Follow by sudo if necessary
gem install cocoapods --verbose # Follow by sudo if necessary
And make sure that your xcodeproj is present:
gem install xcodeproj --verbose # Follow by sudo if necessary
my experience: I had the same error after upgrading to Yosemite, I just did a "gem update" and it worked.
I am trying to create a script that will connect to a remote postgresql server. I am using mavericks os x with postgresql and ruby installed on my local computer, but when I try to load pg into a script like this:
#!/usr/bin/ruby
require 'tk'
require 'tkextlib/tile'
require 'rubygems'
require 'pg'
I get the following error:
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- pg (LoadError)
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from submit.rb:5:in `<main>'
I have installed os x command line tools and ran the following commands:
sudo gem install pg
sudo PATH=$PATH:/Library/PostgreSQL/9.0/bin/ gem install pg
sudo ARCHFLAGS="-arch x86_64" gem install pg
It seems like it installs correctly but it still can't find the pg function. I installed postgresql with brew. My version of ruby is 2.0.0 and psql is 9.3.4.
It looks like your interpreter is running Ruby 2.0. It's possible that your gem installer is an pre-2.0 version and installing your gems to non-2.0 location. You can verify by running
gem -v
If this is the case check if your system has a gem2.0 binary that you can use like so:
sudo gem2.0 install pg
I installed a ruby version as below
$ rvm install ruby-1.9.3-p448-dev
and when i checked version as below
$ ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]
But when i tried to install travis like below
$ gem install travis
Building native extensions. This could take a while...
ERROR: Error installing travis:
ERROR: Failed to build gem native extension.
/home/user/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb
/home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1371:in `initialize': Permission denied - /home/user/.travis/travis.sh (Errno::EACCES)
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1371:in `open'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1371:in `block in copy_file'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1370:in `open'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1370:in `copy_file'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:477:in `copy_file'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:396:in `block in cp'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1515:in `block in fu_each_src_dest'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1529:in `fu_each_src_dest0'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:1513:in `fu_each_src_dest'
from /home/user/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/fileutils.rb:395:in `cp'
from extconf.rb:5:in `<main>'
Gem files will remain installed in /home/user/.rvm/gems/ruby-1.9.3-p448/gems/travis-1.5.2 for inspection.
Results logged to /home/user/.rvm/gems/ruby-1.9.3-p448/gems/travis-1.5.2/completion/gem_make.out
So how to avoid the above native extensions error and install the travis succesfully using gem
Edit
When i tried the command by including sudo as below
sudo gem install travis
I am getting the below message as success
Building native extensions. This could take a while...
Successfully installed travis-1.5.2
1 gem installed
Installing ri documentation for travis-1.5.2...
Installing RDoc documentation for travis-1.5.2...
And now what all i am trying to do is to set up environ variables on travis
and hence i tried the following command
$ travis encrypt -r travis_uname/app_name EMAIL_HOST_KEY=key_value
and getting the below wierd error
/usr/lib/ruby/vendor_ruby/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find travis (>= 0) amongst [addressable-2.3.5, backports-3.3.3, bundler-1.3.5, bundler-unload-1.0.1, coderay-1.0.9, ethon-0.6.0, faraday-0.8.8, faraday_middleware-0.9.0, ffi-1.9.0, gh-0.11.3, highline-1.6.19, launchy-2.3.0, method_source-0.8.2, mime-types-1.24, multi_json-1.7.9, multipart-post-1.2.0, net-http-persistent-2.9, net-http-pipeline-1.0.1, netrc-0.7.7, pry-0.9.12.2, pusher-client-0.3.1, rake-10.1.0, ruby-hmac-0.4.0, rubygems-bundler-1.2.2, rubygems-update-2.0.7, rvm-1.11.3.8, slop-3.4.6, typhoeus-0.6.4, websocket-1.0.7, websocket-native-1.0.0] (Gem::LoadError)
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/dependency.rb:256:in `to_spec'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems.rb:1208:in `gem'
from /usr/local/bin/travis:18
So finally how to avoid above error and make the above travis command work successfully ?
First of all, set the Ruby version you are using as a default
rvm use --default ruby-1.9.3-p448-dev
and uninstall the gem previously installed with sudo
sudo gem uninstall travis
this makes sure that all your commands are using the same Ruby version and your machine is clean again. Now to your installation problem. This error
Permission denied - /home/user/.travis/travis.sh (Errno::EACCES)
shows you, that the installer tried to access /home/user/.travis but wasn't able to do so due to a lack of user permissions. This means you need to make sure that the folder belongs to you and is writeable
chown -R `whoami` ~/.travis
chmod -R u+wx ~/.travis
Now go ahead and try to re-install:
gem install travis
and everything should be fine.
Installing the -dev packages fixed it for me...
sudo apt-get install ruby-dev
It happens sometimes when you install some gems with sudo and other not.
Ideally you should never sudo for the gem install.
So if you have several gems owned by root and you want to remove the ruby installation and the related gems, run this command:
sudo rvm remove ruby-2.0.0-p353 --gems
rvm remove is the preferred way of removing rubies from rvm. By default, not only will it remove the ruby and it's source files, it will also get rid of aliases, wrappers, environments and any associated binaries - in other words, it cleans up most of the install.
The --gems flag will get rid of all associated gemsets.
The you should reinstall your ruby version with:
rvm install ruby-2.0.0-p353
and bundle install again.
I keep getting an error when I run a file called wc.rb. I type:
ruby wc.rb
but I keep getting this error:
/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- nokogiri (LoadError)
from /usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from wc.rb:3:in `<main>'
However, it works when I run the same script with:
sudo ruby wc.rb
Is there anything I can do so that I don't have to run this script as a super user?
When you run with sudo are you running the same version of Ruby? If sudo ruby -v returns something different than ruby -v, you may have only installed the Nokogiri gem in the Ruby 2.0 gem location, and not for the gem location associated with your system's default version of Ruby.
Update: If you originally installed the Nokogiri gem using sudo, you also may need to uninstall it first using sudo (sudo gem uninstall nokogiri) and re-install it without using sudo (gem install nokogiri) for the permissions to be correct.