Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

2nd Perl installation on Mac OSX

by sanjuro (Novice)
on Jun 25, 2009 at 20:39 UTC ( [id://774828]=perlquestion: print w/replies, xml ) Need Help??

sanjuro has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I have a question about using a second Perl installation on a MacOSX system (Leopard). What I've gleaned about MacOSX on this forum and others is that messing around with the default (i.e. /usr/bin/perl) installation of Perl on a Mac could lead to system breakage. I am interested in messing around with Perl, possibly up to the point of breakage, and I don't want to mess the operating system up. So it seems that the most prudent option is to go with a second installation (I'm assuming in /usr/local/bin/perl).

The small complication is that the perl scripts developed on my mac will probably eventually get put on a linux server and I would prefer not to have to remember to modify the scripts themselves to make sure they work as executables on the server. I have outlined a few options below, along with their pros and cons, but would love some input on any options or consequences that I have missed:

1. Make an alias like perl=/usr/local/bin/perl and always run scripts by typing "perl scriptname". This means I don't have to change the #!/usr/bin/perl line in my scripts and there is no danger of the operating system using the wrong perl installation.

2. Use a #!/usr/local/bin/perl or a use lib statement in all of my perl scripts. The downside is that I would have to remember to change them when I put them up on the server, which I'm sure I would forget to do on a regular basis.

3. Change the PATH variable to search /usr/local/bin before /usr/bin. I am worried that this would also point the operating system to the new perl installation and could break things in the same way as modifying the standard perl installation might.

Does anyone have any suggestions or comments?


Thanks!!!
Sanjuro

Replies are listed 'Best First'.
Re: 2nd Perl installation on Mac OSX
by Fletch (Bishop) on Jun 25, 2009 at 21:16 UTC

    Use a shebang of #!/usr/bin/env perl and let env use PATH to find what perl and then just ensure your running environment points to the right place. So long as you're not changing a system-wide config file (e.g. you do it in your account's .bashrc) it shouldn't affect what the OS uses.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: 2nd Perl installation on Mac OSX
by trwww (Priest) on Jun 26, 2009 at 00:41 UTC

    Hello,

    I work on so many different projects that having them each have their own perl install has been very beneficial. It is really simple once you understand the workflow.

    Consider the following directory structure:

    /home/me/projects /home/me/projects/project1 /home/me/projects/project2

    And designate that I want perl dedicated to each project. In each project directory, I have a ./src directory. In that directory, I have a perl source distribution extracted from a tarball downloaded from http://www.cpan.org/src/README.html. In that directory, I run:

    sh Configure -de -Dprefix=/home/me/projects/project1/perl make make install

    After the make install runs, there is a perl isolated from the rest of the system in the directory as specified in the configure command.

    Next, I use a terminal dedicated for that project and set the environment variable PATH to look in the desired directory when I run perl at the terminal. I do this by making a script in the project's bin directory, and sourcing this script:

    $ cat /home/me/projects/project1/bin/environment #!/bin/bash export PATH="/home/me/projects/project1/perl/bin:$PATH" $ chmod 775 /home/me/projects/project1/bin/environment

    Then every time I open a new terminal for this project, I source this environment script:

    $ which perl /usr/bin/perl $ . bin/environment $ which perl /home/me/projects/project1/perl/bin/perl

    Now you have a perl isolated to the given project that will not interfere with the system perl at all.

    There is one other thing that you need to keep in mind: The CPAN configuration for this install. By default, when you run perl -MCPAN -e shell or similar as a non root user, perl will want to put the cpan configuration in /home/me/.cpan. This is okay, but when you have more than one local install of perl (say, project1/perl and project2/perl), using /home/me/.cpan for both will conflict. To remedy this, make sure to use manual configuration when running the given perl's CPAN configuration for the first time, and choose a unique place to store the CPAN configuration directory. I use /home/me/projects/project1/perl/.cpan.

    And now you have a completely isolated perl ready to use for your project that will never bungle up the system's perl. To uninstall this perl, you simply rm -rf /home/me/projects/project1/perl.

    This concept works for applications in general, especially on linux based systems. For example, the popular chat application pidgin has started to have problems connecting to yahoo because of configuration changes at yahoo. The pidgin folks have this problem fixed in the most recent version, but the apt and yum repositories don't have the most recent versions yet. So to solve this problem, you can install a more recent version from source in a unique area using the prefix option to configure, and launch that pidgin. Then when the apt repo gets the fixed version, you can apt-get upgrade the system pidgin and rm -rf the locally installed one.

    Hope this helps!

Re: 2nd Perl installation on Mac OSX
by shoness (Friar) on Jun 25, 2009 at 21:29 UTC
    I suppose you could begin your scripts with:

    #!/usr/bin/env perl
    and let the script execution environment choose via $PATH.

    Cheers!

    Update: Sorry Fletch. I didn't see your response before I replied.

Re: 2nd Perl installation on Mac OSX
by mr_mischief (Monsignor) on Jun 25, 2009 at 21:35 UTC
    Using env as already suggested works. You could also make /usr/local/bin/perl on your Linux server a symlink to /usr/bin/perl if you like (assuming you have the required privileges). It's actually not a bad idea to have a separate installation on most flavors of Linux, either, though.
Re: 2nd Perl installation on Mac OSX
by sanjuro (Novice) on Jun 26, 2009 at 20:37 UTC

    Thanks for all the replies!

    I just want to make sure I have it absolutely right:

    1. Use #!/usr/bin/env perl in my scripts

    2. Put a line in my Mac /Users/Me/.bash_profile that reads "export PATH=/usr/local/bin:$PATH"

    Thanks for the other suggestsions. I don't have anything close to root access on the server so a symlink won't really work and I don't think I need more than one extra perl installation. The alternate shebang notation seems like the right fit for me.

    Thanks again!

    Sanjuro

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://774828]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-24 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found