Ruby and Homebrew error "Refusing to link: openssl" [duplicate] - ruby-on-rails

I'm on: OSX 10.11.6, Homebrew version 0.9.9m OpenSSL 0.9.8zg 14 July 2015
I'm trying to play with with dotnetcore and by following their instructions,
I've upgraded/installed the latest version of openssl:
> brew install openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2h_1.el_capitan.bottle.tar.gz
Already downloaded: /Users/administrator/Library/Caches/Homebrew/openssl-1.0.2h_1.el_capitan.bottle.tar.gz
==> Pouring openssl-1.0.2h_1.el_capitan.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
This formula is keg-only, which means it was not symlinked into /usr/local.
Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include
But when I try to link openssl I continue to run into this linking error:
> brew link --force openssl
Warning: Refusing to link: openssl
Linking keg-only OpenSSL means you may end up linking against the insecure,
deprecated system version while using the headers from the Homebrew version.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
The option to include compiler flags doesn't make sense to me, since I'm not compiling these libraries that I'm dependent on.
EDIT dotnetcore has updated their instructions:
brew update
brew install openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

This is what worked for me:
brew update
brew install openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/Cellar/openssl/1.0.2j/bin/openssl /usr/local/bin/openssl
Thanks to #dorlandode on this thread https://github.com/Homebrew/brew/pull/597
NB: I only used this as a temporary fix until I could spend time correctly installing Openssl again from scratch. As I remember I spent best part of a day debugging and having issues before I realised the best way was to manually install the certs I needed one by one. Please read the link in #bouke's comment before attempting this.

As the update to the other answer suggests, the workaround of installing the old openssl101 brew will no longer work. For a right-now workaround, see this comment on dotnet/cli#3964.
The most relevant part of the issue copied here:
I looked into the other option that was suggested for setting the rpath on the library. I think the following is a better solution that will only effect this specific library.
sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.dylib
and/or if you have NETCore 1.0.1 installed perform the same command for 1.0.1 as well:
sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.1/System.Security.Cryptography.Native.dylib
In effect, rather than telling the operating system to always use the homebrew version of SSL and potentially causing something to break, we're telling dotnet how to find the correct library.
Also importantly, it looks like Microsoft are aware of the issue and and have both a) a somewhat immediate plan to mitigate as well as b) a long-term solution (probaby bundling OpenSSL with dotnet).
Another thing to note: /usr/local/opt/openssl/lib is where the brew is linked by default:
13:22 $ ls -l /usr/local/opt/openssl
lrwxr-xr-x 1 ben admin 26 May 15 14:22 /usr/local/opt/openssl -> ../Cellar/openssl/1.0.2h_1
If for whatever reason you install the brew and link it in a different location, then that path is the one you should use as an rpath.
Once you've update the rpath of the System.Security.Cryptography.Native.dylib libray, you'll need to restart your interactive session (i.e., close your console and start another one).

None of these solutions worked for me on OS X El Capitan 10.11.6. Probably because OS X has a native version of openssl that it believes is superior, and as such, does not like tampering.
So, I took the high road and started fresh...
Manually install and symlink
cd /usr/local/src
If you're getting "No such file or directory", make it:
cd /usr/local && mkdir src && cd src
Download openssl:
curl --remote-name https://www.openssl.org/source/openssl-1.0.2h.tar.gz
Extract and cd in:
tar -xzvf openssl-1.0.2h.tar.gz
cd openssl-1.0.2h
Compile and install:
./configure darwin64-x86_64-cc --prefix=/usr/local/openssl-1.0.2h shared
make depend
make
make install
Now symlink OS X's openssl to your new and updated openssl:
ln -s /usr/local/openssl-1.0.2h/bin/openssl /usr/local/bin/openssl
Close terminal, open a new session, and verify OS X is using your new openssl:
openssl version -a

Just execute brew info openssland read the information where it says:
If you need to have this software first in your PATH run: echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

If migrating your mac breaks homebrew:
I migrated my mac, and it unlinked all my homebrew installs - including OpenSSL. This broke gem install, which is how I first noticed the problem and started trying to repair this.
After a million solutions (when migrating to OSX Sierra - 10.12.5), the solution ended up being comically simple:
brew reinstall ruby
brew reinstall openssl
Edit much later: as Gal Bracha noted in the comments, you ?might? need to delete /usr/local/opt/openssl before doing the reinstalls, just to be safe. I didn't need to at the time, but if you're still having trouble, give that a try.

After trying everything I could find and nothing worked, I just tried this:
touch ~/.bash_profile; open ~/.bash_profile
Inside the file added this line.
export PATH="$PATH:/usr/local/Cellar/openssl/1.0.2j/bin/openssl"
now it works :)
Jorns-iMac:~ jorn$ openssl version -a
OpenSSL 1.0.2j 26 Sep 2016
built on: reproducible build, date unspecified
//blah blah
OPENSSLDIR: "/usr/local/etc/openssl"
Jorns-iMac:~ jorn$ which openssl
/usr/local/opt/openssl/bin/openssl

The solution above from edwardthesecond worked for me too on Sierra
brew install openssl
cd /usr/local/include
ln -s ../opt/openssl/include/openssl
./configure && make
Other steps I did before were:
installing openssl via brew
brew install openssl
adding openssl to the path as suggested by homebrew
brew info openssl
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

I have a similar case. I need to install openssl via brew and then use pip to install mitmproxy. I get the same complaint from brew link --force. Following is the solution I reached: (without force link by brew)
LDFLAGS=-L/usr/local/opt/openssl/lib
CPPFLAGS=-I/usr/local/opt/openssl/include
PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig
pip install mitmproxy
This does not address the question straightforwardly. I leave the one-liner in case anyone uses pip and requires the openssl lib.
Note: the /usr/local/opt/openssl/lib paths are obtained by brew info openssl

This worked for me:
brew install openssl
cd /usr/local/include
ln -s ../opt/openssl/include/openssl .

By default, homebrew gave me OpenSSL version 1.1 and I was looking for version 1.0 instead. This worked for me.
To install version 1.0:
brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
Then I tried to symlink my way through it but it gave me the following error:
ln -s /usr/local/Cellar/openssl/1.0.2t/include/openssl /usr/bin/openssl
ln: /usr/bin/openssl: Operation not permitted
Finally linked openssl to point to 1.0 version using brew switch command:
brew switch openssl 1.0.2t
Cleaning /usr/local/Cellar/openssl/1.0.2t
Opt link created for /usr/local/Cellar/openssl/1.0.2t

I had the same problem while trying to install newer version of ruby 2.6.5
https://github.com/kelaberetiv/TagUI/issues/86 helps me to solve the problem. This if for macOS catalina Version 10.15.1
Basically, I did update and upgrade homebrew and install openssl and install ruby.
brew update && brew upgrade
brew install openssl
Then create these 2 symlinks
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
then installed ruby 2.6.5

Note: this no longer works due to https://github.com/Homebrew/brew/pull/612
I had the same problem today. I uninstalled (unbrewed??) openssl 1.0.2 and installed 1.0.1 also with homebrew. Dotnet new/restore/run then worked fine.
Install openssl 101:
brew install homebrew/versions/openssl101
Linking:
brew link --force homebrew/versions/openssl101

for me this is what worked...
I edited the ./bash_profile and added below command
export PATH="/usr/local/opt/openssl/bin:$PATH"

export https_proxy=http://127.0.0.1:1087 http_proxy=http://127.0.0.1:1087 all_proxy=socks5://127.0.0.1:1080
works for me
and I think it can solve all the problems like
Failed to connect to raw.githubusercontent.com port 443: Connection refused

The solution might be updating some tools.
Here's my scenario from 2020 with Ruby and Python:
I needed to install Python 3 on Mac and things escalated. In the end, updating homebrew, node and python lead to the problem with openssl. I did not have openssl 1.0 anymore, so I couldn't "brew switch" to it.
So what was still trying to use that old 1.0 version?
It tuned out it was Ruby 2.5.5.
So I just installed Ruby 2.5.8 and removed the old one.
Other things you can try if this is not enough: Use rbenv and pyenv. Clean up gems and formulas. Update homebrew, node, yarn. Upgrade bundler. Make sure your .bash_profile (or equivalent) is set up according to each tool's instructions. Reopen the terminal.

Related

FFI::NotFoundError (Function 'OPENSSL_init_ssl' not found in [libssl.dylib])

I'm using Mac OS for development. Now I'm developing an app using Blockcypher API. With Ruby on Rails, when I try to send money using the Gem, it always return this error
FFI::NotFoundError (Function 'OPENSSL_init_ssl' not found in [libssl.dylib])
Already try to upgrade or downgrade the OpenSSL version on my mac but nothing happend and it so frustating. My friend on linux doesn't get this error, work perfectly on his device. Has anyone ever got this error?
I had the same problem, after research for one day I found the solution for rvm ruby-2.7.2 version:
Install openssl version 1.1:
brew update & brew upgrade & brew install openssl#1.1
cd in your openssl lib folder in my case: /usr/local/opt/openssl#1.1/lib
copy files to /usr/lib
cd /usr/local/opt/openssl#1.1/lib
Copy the libssl.1.1.dylib file
sudo cp libssl.1.1.dylib libcrypto.1.1.dylib /usr/local/lib/
make softlink
sudo ln -s libssl.1.1.dylib libssl.dylib
sudo ln -s libcrypto.1.1.dylib libcrypto.dylib
Reinstall ruby with openssl version:
rvm reinstall 2.7.2 --with-openssl-dir=/usr/local/opt/openssl#1.1
References github issues, stackoverflow.

Trouble with brew install devil

RGBDSLAM install is asking for devil
$ rosdep install rgbdslam
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
rgbdslam: No definition of [libdevil-dev] for OS [osx]
But when I try to install devil I'm getting this:
$ brew install devil
Error: devil cannot be built with any available compilers.
To install this formula, you may need to:
brew install gcc
$ brew install gcc
Warning: gcc-5.3.0 already installed
How can I get around this?
Note: I have xcode installed accompanied with the command line tools.
** EDIT libdevIL installed **
for some reason gcc 5 doesn't register when devIL is looking for gcc so I had to downgrade to 4.9.
$ brew rm gcc // removes 5
$ brew install gcc49 // installs 4.9
$ brew install devil // works
$ brew install gcc // two gcc installed? this might be interesting
rgbdslam still isn't detecting libdevIL though, not sure what the deal is.
Here's some helpful notes from answers.ros.org
I set siftgpu_disable_devil = 0 in SiftGPU/makefile and
set(ENV{SIFT_GPU_MODE} 0) in CMakeLists.txt with no avail. I'm
still seeing rgbdslam: No definition of [libdevil-dev] for OS [osx]
Commenting devIL out in package.xml put me a little further but
into some seemingly OSX specific issues, trying to resolve those via
github. Will respond here once I have a solution. Thanks for your
assistance.

Error installing CouchDB with homebrew osx 10.8 - skip dependency?

So I tried to install it according to the directions on couchdb wiki. and I get the following issue
Installing couchdb dependency: erlang-r15
==> Downloading https://github.com/erlang/otp/archive/OTP_R15B03-1.tar.gz
Already downloaded: /Library/Caches/Homebrew/erlang-r15-R15B03-1.tar.gz
Error: SHA1 mismatch
Expected: 5ba866722de79956b06966c232490d32bb7ba0a6
Actual: 7843070f5d325f95ef13022fc416b22b6b14120d
Archive: /Library/Caches/Homebrew/erlang-r15-R15B03-1.tar.gz
Is there anyway to tell brew to skip this dependency since I have already installed the correct version of erlang, and it can't see it?
Did you try brew uninstall couchdb and re install after?
I had the same issue, it fixed it for me
So to get this working I followed the instruction on the couchdb until the install couchdb command:
brew remove --force openssl erlang couchdb icu4c spidermonkey nspr
brew update
brew outdated
brew rm --force erlang
cd /usr/local
git checkout 168742f Library/Formula/erlang.rb
brew install erlang
since I knew I had the right erlang installed I altered the Bew formula to make it work correctly.
So I headed over to the formula at
vim /usr/local/Library/Formula/couchdb.rb
And altered the dependency line
depends_on 'erlang-15'
to
depends_on 'erlang'
and works great now!!
None of the solutions here worked for me, but the below did. Note, I had to build with unixodbc.
brew remove --force openssl erlang couchdb icu4c spidermonkey
brew update
brew install unixodbc
brew install homebrew/versions/erlang-r15 --with-unixodbc
# edit /usr/local/Library/Formula/couchdb.rb to change depends_on to 'erlang-r15'
brew install couchdb
You may want to first try force removing only erlang and couchdb -- as someone in this thread mentioned that force removing packages messed up his system (though I did not encounter this problem when running the above instructions).

Rails + Mac OS X: libMagickCore-Q16.7.dylib doesn't work

If I run some kind of rake command, I get this error message:
rake aborted!
dlopen(/Users/adam/.rvm/gems/ruby-1.9.3-p327/gems/rmagick-2.13.1/lib/RMagick2.bundle, 9): Library not loaded: /usr/local/lib/libfreetype.6.dylib
Referenced from: /usr/local/lib/libMagickCore-Q16.7.dylib
Reason: Incompatible library version: libMagickCore-Q16.7.dylib requires version 16.0.0 or later, but libfreetype.6.dylib provides version 13.0.0 - /Users/adam/.rvm/gems/ruby-1.9.3-p327/gems/rmagick-2.13.1/lib/RMagick2.bundle
...
I am running on RoR 3.2, OSX Lion.
Could anyone help me, please, how to fix this issue? I spent 2 days of googling, reading discussions, but unfortunately with zero success...
Thank you so much!
Using Homebrew I was able to solve it using the following commands:
brew uninstall freetype
brew update
brew install freetype
Update step might be unnecessary. The installation succeeded but with the following warning:
Warning: Could not link freetype. Unlinking...
So one final command:
brew link --overwrite freetype
I have an amazing how-to-install-rmagick that have been working beautifully for me, try to re-install ImageMagick following these steps:
yum install tcl-devel libpng-devel libjpeg-devel ghostscript-devel bzip2-devel freetype-devel libtiff-devel -y (I use CentOS, you can translate the commands to your distro)
Download ImageMagick. Write wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz and press Enter. ImageMagick.tar.gz is created in the current directory.
Unpack the ImageMagick archive. Write tar xczf ImageMagick.tar.gz and press Enter. A new directory, ImageMagick-version, where version is the ImageMagick version number, is created.
Switch to the ImageMagick directory. Write cd ImageMagick-version and press Enter.
Configure the ImageMagick build. Write ./configure --prefix=/usr/local --without-perl and press Enter.
Compile ImageMagick. Write make and press Enter. ImageMagick compiles. This step may take several minutes.
Install ImageMagick to your home directory. Write make install and press Enter.
Remove the installation files. Write rm -r ImageMagick.tar.gz and press Enter.
Add /usr/local/bin to your PATH.
Write echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile and press Enter.
Reload your .bash_profile. Write source ~/.bash_profile and press Enter.
Install the RMagick gem.
Write export LD_LIBRARY_PATH=/usr/local/lib and press Enter.
Write export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ and press Enter.
Install the RMagick gem in your Ruby on Rails application.
Tell me later how it goes.
I found the answer in another post:
Rails 3 - RMagick doesn't find libfreetype.6.dylib using Paperclip
I performed the search and found that there was an older version of libfreetype that was being referenced and newer versions hidden elsewhere. By copying/linking the newer versions into the appropriate directory (/usr/local/lib in my case) the problem was resolved.
Do you use something like Homebrew or MacPorts to manage external library dependencies?
Installing the imagemagick library from there and then install rmagick.

How do I uninstall openssl in /usr/lib?

After installing the pg gem, I'm getting this error when I try to start the server on my local machine:
/Users/foo/.rvm/gems/ree-1.8.7-2011.12/gems/pg-0.14.0/lib/pg_ext.bundle: dlopen(/Users/foo/.rvm/gems/ree-1.8.7-2011.12/gems/pg-0.14.0/lib/pg_ext.bundle, 9): Library not loaded: #loader_path/../lib/libssl.dylib (LoadError)
Referenced from: /usr/lib/libpq.5.dylib
Reason: Incompatible library version: libpq.5.dylib requires version 1.0.0 or later, but libssl.dylib provides version 0.9.8 - /Users/foo/.rvm/gems/ree-1.8.7-2011.12/gems/pg-0.14.0/lib/pg_ext.bundle
I have an up to date version of openssl installed on my machine via macports but it seems like the gem is looking at the older version that I have installed in /usr/lib for some reason (maybe something to do with a messed up #loader_path?).
'openssl version' gives me 'OpenSSL 1.0.1c 10 May 2012'
and 'which openssl' gives me '/opt/local/bin/openssl' as I expected
Any help is really appreciated. Thanks!
I just ran into this problem after updating to Mountain Lion. After checking that I had a proper OpenSSL version, I did the following.
$ ls /Library/PostgreSQL/9.1/lib/libssl*
Provided the following:
/Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib
/Library/PostgreSQL/9.1/lib/libssl.dylib
/Library/PostgreSQL/9.1/lib/libssl.a
I copied the file as so:
$ sudo cp /Library/PostgreSQL/9.1/lib/libssl.1.0.0.dylib /usr/lib/
Then linked:
$ cd /usr/lib
$ ln -sf libssl.1.0.0.dylib libssl.dylib
After that, I tried rails s again and the same error came up with a different file, so I repeated the process (libcrypto):
requires version 1.0.0 or later, but libcrypto.0.9.8.dylib
provides version 0.9.8
so:
$ sudo cp /Library/PostgreSQL/9.1/lib/libcrypto.1.0.0.dylib /usr/lib/
$ cd /usr/lib
$ ln -sf libcrypto.1.0.0.dylib libcrypto.dylib
See this question's answers for reference as well:
python pip install psycopg2 install error

Resources