I banged my head on this stupid problem for months. It all came about after upgrading my Macbook from Leopard to Snow Leopard (OSX 1.6). I was plagued with this error here and there when I wanted to compile certain software (namely imagemagick and mysql) or install certain native Ruby gem. It was a nightmare, but it seemed I would have to live with it, until I could find the time to reinstall Snow Leopard from scratch.
Google reveals very little useful information for dealing with this error. Everyone seems to have the problem, and yet fixes seem quite elusive. I finally hit upon a fix that worked for me and I’ll share it here in case the solution also works for others. First thing you’ll want to do is install xCode, the developer SDK from Apple. Download the most recent version from the Apple Developer site, as the version on disk might be old. You’ll need the OSX 10.6 libraries. After xcode is installed go to the directory that the problemed libz.dylib file is found and rename it so you have a backup in case things get messed up worse and you need to restore it:
cd /usr/local/lib/libz.dylib sudo mv libz.dylib libz.dylib.original
Now, when you installed xCode it should have also installed a recent version of libz.dylib in among the SDK files. So the next step is to copy that version of the file to replace the file we just renamed.
sudo cp -rf /Developer/SDKs/MacOSX10.6.sdk/usr/lib/libz.dylib .
That’s it. Go ahead and try to install that pesky ruby gem (rmagick) that wasn’t installing or compile ImageMagick. If you are lucky like me, it should work. I hope this saves some folks a lot of hair pulling. Let me know how it goes!
This may also work for some other dylib files that are problematic such as libexpat.dylib. Just take a look in the lib directory of the OSX 10.6 SDK and see if the file exists. Remember to things up before replacing swapping in the new files.
Thanks for this post. It saved me a lot of time. FYI, it seems my libz was installed in /opt/local/lib/ . Nevertheless, I copied the original libz.dylib from OSX10.6 as per your experience and it worked as well.
-rwxrwxr-x 2 root admin 83040 28 Apr 2008 libz.1.2.3.dylib
lrwxr-xr-x 1 root admin 16 28 Apr 2008 libz.1.dylib -> libz.1.2.3.dylib
-rwxrwxr-x 2 root admin 83232 28 Apr 2008 libz.a
-rwxr-xr-x 1 rupert admin 23852 3 Mar 21:53 libz.dylib
Cheers,
rupert
Thank you, I was banging my head trying to get the mysql gem installed after upgrading to Snow Leopard as well and this works great.
Note: I had to do the same for libz.1.dylib + libz.1.2.3.dylib to get the pg (postgres) gem to install.
Are you using MacPorts? You may need to migrate your old binaries. See the MacPorts migration docs:
https://trac.macports.org/wiki/Migration
And here’s a script that may ease the pain:
http://andyic.org/wordpress/index.php/2010/06/macports-migration/
Why not just delete the bad copy of zlib? A fresh install of OS X has nothing in /usr/local.
Thanks a lot! I was having a problem compiling nokogori native extensions, copying libz.1.dylib as you suggest solves the problem. I didn’t try Josh’s technique.
Thanks! This fixed my nokogiri problem too. I did those steps for libz.1.dylib + libz.1.2.3.dylib as well, like Jordan Brough did.
Thank you. My recent attempt to compile Io did not like the libz I had. It complained about it not being x86_64. Your tip lead me to a 64 bit libz that mad it happy.
THANK YOU SO MUCH. I had to do this to fix my nokogiri problem as well. You’re a legend!
Thanks for saving me a lot of time.
Thanks man! I spent 4 hours on this issue. Luckily I stopped by your site. thanks
Thanks a lot. Was pulling out my hair in clumps.
Also worth noting that like rupert I found the files in /opt/local/lib/. Might be worth updating the post for anyone who misses the comments.