Installing Perl/Tk (and other stuff) on OSX
I have used Perl and Perl/Tk for several years. It was one of the reasons that I swapped over to OSX from Linux. Unfortunately, the Apple engineers don't make it easy. Many times incremental updates to OSX will break it, and major upgrades to a new version of Cat always do.
So, here is an easy way to install an independent Perl on your system in the Home folder that will be out of the line of fire by the App Store. It won't change OSX in any way so you won't unhook the Apple Perl installation.
If you want to get rid of all of it, just dump ~/home/perl5 in the trash and take the source line out of .bash_profile. Your system will be back like it was before you started.
1. Install Xcode. If you want to hack, you don't need the entire suite and you can just install the Unix utilities. But, I have found that this usually gets wrecked on the next update of Xcode. So, I recommend that you get the whole thing.
The following commands are run in a terminal window.
2. Install perlbrew with the command… (you can visit the website with Perlbrew . I know that doesn't look like a URL, but it is.)
curl -kL http://install.perlbrew.pl | bash
3. After the above install, put the following into your ~/home/.bash_profile. You will probably have to create the file, since most installs of OSX don't have it.
Exit the terminal window and start another so your login reads the new .bash_profile
4. Load which ever perl you want, with… (5.14.2 is the latest stable as of this writing.)
perlbrew install perl-5.14.2
5. Tell your system about it with...
perlbrew switch perl-5.14.2
Note that you can load as many different perl versions as you wish.
Log out of your current terminal, then open up another one, so your .bash_profile gets read.
…and you should get something like this...
…bunch of stuff...
You should be ready to go.
In your perl program bang line, replace #!/usr/bin/perl with #!/Users/home/perl5/perlbrew/perls/perl-5.14.2/bin/perl
This is the way to point your script to which ever perl you want to use. In this case, 5.14.2
Now, just install Tk (or any other CPAN module) the usual way with perl Makefile.PL, make, make test and make install. The make install now doesn't have to be done with root authority.
This install was tested on Lion and should work on Leopard, Snow Leopard, and survive the upgrade to Mountain Lion.
But, I do it the manual way so I can maintain the exact same environment between OSX, Linux and BSD. In the past, that was valuable since I could continue to develop on a much less pleasant to to use Linux desktop while I was trying to figure out just what the new Xcode or update had done to my OSX setup.
But either way works fine as long as Perl and modules load and run. I just posted because of all the hits I was seeing on other forums about "Why does XXX.pm refuse to load on Snow Leopard..." and so forth.
Hmm, this must be a Perl specific issue since I've never experienced this kind of problem with Python (although, I'm waiting for the day when Apple ships OS X with Python 3...that should be fun). It sucks that you have to go through all of this just to maintain a reasonable Perl installation.
Thanks for the tip. How much of a pain is it with an odd shebang line (for portability)?
For a developer working outside of Xcode, it is always a pain on OSX. Even if you change the bang line back to the usual /usr/bin/perl, you have no guarantee of where external modules reside on the target machine - or even if they exist at all. I have enough trouble trying to get modules and links to migrate to the next version of OSX, without even thinking about trying to get it to run on someone else's machine.
If you are are just coding plain Perl, then you might just as well stick to the OSX version and it will work fine. But if you use external modules, then you are probably up the creek. You would almost have to publish (to a non Perl/OSX techie) a whole set of documentation of how install the needed modules to make your code work. Once they saw that, I doubt that they would even download your code, let alone install it.
I don't think that Apple is anti Perl (or Python or Ruby or...), just that they don't worry about anything outside of Xcode. Kind of like Microsoft's attitude for years of, "If you aren't running Visual Basic or Visual C, then why are you bothering to write a program?"
It actually worked. For the first time, an upgrade didn't require me to find a patched version of something, or hunt down where the libraries had been moved, or google for hours to find out what Apple had done.
The move from Lion to Mountain Lion unhooked XQuartz, but that was just a matter of clicking on the dmg again. But everything else is still happily running inside of my home folder. Shoulda done this years ago.
|All times are GMT -4. The time now is 03:40 AM.|
Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.