Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   Installing Perl/Tk (and other stuff) on OSX (http://www.mac-forums.com/forums/os-x-development-darwin/279400-installing-perl-tk-other-stuff-osx.html)

cptkrf 07-15-2012 11:58 PM

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.
source ~/perl5/perlbrew/etc/bashrc

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.

Run…
perl -V
…and you should get something like this...

…bunch of stuff...

@INC:
/
/Users/home/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2/darwin-2level
/Users/home/perl5/perlbrew/perls/perl-5.14.2/lib/site_perl/5.14.2
/Users/home/perl5/perlbrew/perls/perl-5.14.2/lib/5.14.2/darwin-2level
/Users/home/perl5/perlbrew/perls/perl-5.14.2/lib/5.14.2




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.

vansmith 07-16-2012 10:02 AM

Wouldn't installing something like ActivePerl obviate the need to do something like this? They even have Tk available in their PPM (here).

cptkrf 07-16-2012 11:03 AM

Quote:

Originally Posted by vansmith (Post 1425390)
Wouldn't installing something like ActivePerl obviate the need to do something like this? They even have Tk available in their PPM (here).

Of course. And it works well. You still have the problem of breakage on occasion when Apple pulls the rug out from under the Unix utilities, but it is easy to just reinstall. I have seen some .pm modules that wouldn't run under ActivePerl, but they were fairly obscure code that few people would use, and most of the problems seemed to be that ActivePerl was Windows-centric for a long time and a few vestiges of that still remain in the current downloads.

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.

vansmith 07-16-2012 11:27 AM

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)?

cptkrf 07-23-2012 09:17 PM

Quote:

Originally Posted by vansmith (Post 1425422)
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 me it is no pain at all, since I only code for myself on the Mac that will run the code.

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?"

vansmith 07-24-2012 10:05 AM

Quote:

Originally Posted by cptkrf (Post 1428006)
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.

Ah, this is where me and you differ. I only use the standard library or modules that can be easily migrated. I rarely script for anyone else but I want there to be the option of doing so. ;)

cptkrf 08-05-2012 10:00 AM

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.