Difference between revisions of "Perlbrew"

From HalfgeekKB
Jump to navigation Jump to search
 
(17 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
'''perlbrew''' is a manager for [[sudo]]-free, user-level perl installations.
 
'''perlbrew''' is a manager for [[sudo]]-free, user-level perl installations.
 +
 +
==Hope you're patient==
 +
 +
Some of these steps take a ''very'' long time and, unless you're lucky, more than one attempt.
  
 
==Installation==
 
==Installation==
Line 9: Line 13:
 
wget --no-check-certificate https://raw.github.com/gugod/App-perlbrew/master/perlbrew
 
wget --no-check-certificate https://raw.github.com/gugod/App-perlbrew/master/perlbrew
 
perl perlbrew self-install
 
perl perlbrew self-install
cat 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bashrc # restart bash for this to take effect
+
</syntaxhighlight>
 +
 
 +
The install will suggest that you source something from your shell startup, which may vary depending on your current shell. Follow the instructions given and restart your shell.
 +
 
 +
<syntaxhighlight lang=bash>
 +
# Two possibilities
 +
echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bash_profile
 +
echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bashrc
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 45: Line 56:
  
 
<syntaxhighlight lang=bash>
 
<syntaxhighlight lang=bash>
perlbrew install -D useshrplib --as $your_install_name stable
+
perlbrew install -D useshrplib -D usesitecustomize --as $your_install_name stable
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
* The <code>--as</code> switch is optional. Omitting it causes the version to be used instead of a name when managing.
 
* The <code>--as</code> switch is optional. Omitting it causes the version to be used instead of a name when managing.
* <code>-D useshrplib</code> enables compiling Perl in terms of a shared library, libperl.so. Optional, but don't omit it without a good reason.
+
* <code>-D useshrplib</code> enables compiling perl in terms of a shared library, libperl.so. Optional, but don't omit it without a good reason.
 
** Other <code>-D</code>, <code>-U</code>, <code>-A</code> defines are passed the same way.
 
** Other <code>-D</code>, <code>-U</code>, <code>-A</code> defines are passed the same way.
 
** <code>--thread</code>, <code>--multi</code> can also be passed here.
 
** <code>--thread</code>, <code>--multi</code> can also be passed here.
 +
* <code>-D usesitecustomize</code> enables having this perl automatically run a pre-script, <code>$Config{siteperl}/sitecustomize.pl</code>, before nearly anything else. See -f in perlrun.
 +
** <code>--sitecustomize ''filename''</code> does this and will also install the given file as sitecustomize.pl.
 
* The <code>stable</code> specifier may be replaced with any version number or <code>blead</code>.
 
* The <code>stable</code> specifier may be replaced with any version number or <code>blead</code>.
 
** It can also be replaced with the ''fully qualified path or URL'' of a .tar.gz (or .tar.bz2, etc.) archive of a Perl distribution. If the archive is in the current directory, use e.g. <code>"`pwd`"/perl-x.x.x.tar.gz</code> rather than <code>./perl-x.x.x.tar.gz</code>; otherwise, it won't be recognized.
 
** It can also be replaced with the ''fully qualified path or URL'' of a .tar.gz (or .tar.bz2, etc.) archive of a Perl distribution. If the archive is in the current directory, use e.g. <code>"`pwd`"/perl-x.x.x.tar.gz</code> rather than <code>./perl-x.x.x.tar.gz</code>; otherwise, it won't be recognized.
Line 60: Line 73:
  
 
I believe it is supposed to work to install the same version twice as long as the names are different. However, there can be only one build directory per version, so don't try to perform the actual installs simultaneously; wait for one to finish before starting the next.
 
I believe it is supposed to work to install the same version twice as long as the names are different. However, there can be only one build directory per version, so don't try to perform the actual installs simultaneously; wait for one to finish before starting the next.
 +
 +
===Making the install INSTALL_BASE-friendly (or: extra @INC paths)===
 +
 +
When using the INSTALL_BASE parameter on perl module installation (in particular, for modules installed outside cpan such as the Image::Magick example), the installer wants to install stuff in, among other paths,
 +
 +
$INSTALL_BASE/lib/perl5
 +
$INSTALL_BASE/lib/perl5/''architecture''
 +
 +
Unfortunately, these aren't in the default @INC because the simplified install dirs scheme is used (see INSTALL, Installation Directories, scan for "slightly simplified").
 +
 +
====Symlink to a directory already in @INC====
 +
 +
If the perl has already been compiled, it should work to use a symlink from the current version number to <code>perl5</code> before trying to install anything:
 +
 +
<syntaxhighlight lang=bash>
 +
cd ~/perl5/perlbrew/perls/installname/lib
 +
ln -s site_perl/5.*.* perl5
 +
# or ln -s 5.*.* perl5
 +
</syntaxhighlight>
 +
 +
This approach seems sane and simple enough that it's probably the one I'm going to use.
 +
 +
====Add to @INC using site customization====
 +
 +
If the perl was compiled with <code>usesitecustomize</code>, @INC manipulations can be made directly to lib/site_perl/sitecustomize.pl.
 +
 +
The potential utility of something like this warrants always compiling with this option.
 +
 +
====Add to @INC when compiling====
 +
 +
If the perl hasn't been compiled yet, you might consider a compile-time mechanism like <code>-Dotherlibdirs</code> to add paths to @INC.
  
 
==Remove an install==
 
==Remove an install==
Line 68: Line 112:
  
 
Simple.
 
Simple.
 +
 +
==Using on Cygwin==
 +
 +
Tricky, and so far I haven't succeeded. Points to note:
 +
 +
===Version===
 +
 +
5.18.2
 +
 +
===PATH===
 +
 +
Before attempting to build, ensure PATH contains no spaces or parentheses in order to prevent a shell syntax problem. On Cygwin, this appears to generally mean cutting out all components containing "cygdrive".
 +
 +
===cd to build dir===
 +
 +
On the first failure, cd into the path perlbrew says to use for installing without tests.
 +
 +
===Fix for nostdio.h hack===
 +
 +
The only actual build issue is given as a syntax issue at nostdio.h. nostdio.h is a set of hacks designed to prevent subsequent includes of stdio.h by making all usages thereof errors.
 +
 +
One of the hacks used around line 25 causes some choking:
 +
 +
<syntaxhighlight lang=c>
 +
#define FILE struct _FILE
 +
</syntaxhighlight>
 +
 +
[http://www.nntp.perl.org/group/perl.cpan.testers.discuss/2014/04/msg3342.html It is mentioned elsewhere] that defining <code>PERLIO_NOT_STDIO</code> to 0 in cygwin.h near the beginning temporarily disables the hack in one problematic place.
 +
 +
<syntaxhighlight lang=c>
 +
#define PERLIO_NOT_STDIO 0
 +
</syntaxhighlight>
 +
 +
===Continue build===
 +
 +
Do <code>make</code> here. The build should succeed.
 +
 +
Do <code>make test</code> if you like. Some test problems are apparently unavoidable.
  
 
==Fixes for build failures==
 
==Fixes for build failures==
Line 109: Line 191:
 
==Image::Magick==
 
==Image::Magick==
  
One process that is claimed to work for installing Image::Magick is given [http://perltricks.com/article/57/2014/1/1/Shazam-Use-Image-Magick-with-Perlbrew-in-minutes on perltricks.com].
+
One process that is claimed to work for installing [[ImageMagick|Image::Magick]] is given [http://perltricks.com/article/57/2014/1/1/Shazam-Use-Image-Magick-with-Perlbrew-in-minutes on perltricks.com].
  
The given process has a new IM library installed under ~/local. I'm likely to modify it to something like ~/opt/ImageMagick-VERSION-NAME. This should be documented here.
+
The given process has a new IM library installed under ~/local. I've changed it to ~/opt/ImageMagick-''VERSION''-''NAME'' to make it possible to install a different instance per perl install. I've also specified a font path.
 
 
Proposed install script (currently testing):
 
  
 
<syntaxhighlight lang=bash>
 
<syntaxhighlight lang=bash>
Line 120: Line 200:
 
OPT="$HOME/opt"
 
OPT="$HOME/opt"
 
FONT_PATH="$HOME/.fonts"
 
FONT_PATH="$HOME/.fonts"
PB_NAME="your perlbrew install name"
+
PB_NAME="perlbrew install name"
 
PB_DIR="$PERLBREW_ROOT/perls/$PB_NAME"
 
PB_DIR="$PERLBREW_ROOT/perls/$PB_NAME"
 
PB_PERL="$PB_DIR/bin/perl"
 
PB_PERL="$PB_DIR/bin/perl"
Line 127: Line 207:
 
   
 
   
 
WITHOUT_THREADS=`"$PB_PERL" -MConfig -E '$Config{useithreads} or say "--without-threads"'`
 
WITHOUT_THREADS=`"$PB_PERL" -MConfig -E '$Config{useithreads} or say "--without-threads"'`
 +
ENABLE_SHARED=`"$PB_PERL" -MConfig -E '$Config{useshrplib} eq "true" and say "--enable-shared"'`
 +
unset PERL5LIB
 +
echo Current PERL5LIB: "$PERL5LIB"
  
 
CONFIGURE="LDFLAGS=-L'$PB_CORE' \
 
CONFIGURE="LDFLAGS=-L'$PB_CORE' \
./configure $WITHOUT_THREADS \
+
./configure $WITHOUT_THREADS $ENABLE_SHARED \
 
--prefix '$PREFIX' \
 
--prefix '$PREFIX' \
 
--with-perl='$PB_PERL' \
 
--with-perl='$PB_PERL' \
--enable-shared \
+
--with-perl-options=INSTALL_BASE='$PB_DIR' \
 
--with-fontpath='$FONT_PATH' \
 
--with-fontpath='$FONT_PATH' \
 
--with-rsvg"
 
--with-rsvg"
Line 138: Line 221:
 
echo Our configure command looks like:
 
echo Our configure command looks like:
 
echo "$CONFIGURE"
 
echo "$CONFIGURE"
read -p "Press enter if this looks right (especially LDFLAGS and threads)." &&
+
read -p "Press enter if this looks right." &&
 
wget "$IM_DOWNLOADS/$IM.tar.xz" &&
 
wget "$IM_DOWNLOADS/$IM.tar.xz" &&
 
tar xJvf "$IM.tar.xz" &&
 
tar xJvf "$IM.tar.xz" &&
Line 145: Line 228:
 
read -p "Press enter to make and install." &&
 
read -p "Press enter to make and install." &&
 
make install
 
make install
 +
</syntaxhighlight>
 +
 +
If retrying any step after the configure without rerunning the script, at least make sure PERL5LIB is unset. Otherwise, the install will attempt to bring in perl stuff from the system perl, and dumb errors like <code>undefined symbol: Perl_Istack_sp_ptr</code> will ruin your day.
 +
 +
To verify the install, the article suggests running the perl and requesting a way-too-high version of the module Image::Magick::Q16 (at least, as of this version if IM, that's where the version information actually is).
 +
 +
<nowiki>
 +
$ ~/perl5/perlbrew/perls/installname/bin/perl -MImage::Magick::Q16\ 999
 +
Image::Magick::Q16 version 999 required--this is only version 6.89.
 +
BEGIN failed--compilation aborted.</nowiki>
 +
 +
If the error is about the version and not about the module seeming installed, you're good.
 +
 +
==LWP::Protocol::https==
 +
 +
No special treatment needed, but see [[#Net::SSLeay]] if you need to use a non-system OpenSSL build.
 +
 +
==Net::SSLeay==
 +
 +
The shared hosting provider may have omitted the OpenSSL dev headers from the system, requiring you to build your own OpenSSL. When this happens, Net::SSLeay won't install properly unless you specify the path as <code>OPENSSL_PREFIX</code>.
 +
 +
Note that this refers to the same dir as the <code>PREFIX</code> from the OpenSSL install. (For example, the file <code>$OPENSSL_PREFIX/include/openssl/x509.h</code> should exist.)
 +
 +
<syntaxhighlight lang=bash>
 +
# I installed OpenSSL to its own subdir of ~/opt
 +
OPENSSL_PREFIX=/home/someuser/opt/openssl-1.0.1k cpanm Net::SSLeay
 +
</syntaxhighlight>
 +
 +
(This problem isn't specific to perlbrew, but the system perl usually already has a working Net::SSLeay.)

Latest revision as of 08:20, 12 January 2015

perlbrew is a manager for sudo-free, user-level perl installations.

Hope you're patient

Some of these steps take a very long time and, unless you're lucky, more than one attempt.

Installation

Directly

cd ~/tmp
wget --no-check-certificate https://raw.github.com/gugod/App-perlbrew/master/perlbrew
perl perlbrew self-install

The install will suggest that you source something from your shell startup, which may vary depending on your current shell. Follow the instructions given and restart your shell.

# Two possibilities
echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bash_profile
echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bashrc

At this point, you should continue to Accessories below, but the commands failed for me because of a certificate issue. This issue can be worked around by patching perlbrew to skip SSL cert checks in wget and curl modes (and not have fetch installed).

perl -i -p -E 's/(--silent --location)/-k $1/g; s/(--quiet -O)/--no-check-certificate $1/g' ~/perl5/perlbrew/bin/perlbrew

CPAN

Note: I couldn't get this working on dreamhost; there were tests that failed.

The CPAN install is more involved, but it is also not minified, which should make any necessary debugging easier.

Install using the CPAN for the system's main perl, not one of the perlbrew perls.

perlbrew off # If perlbrew is already installed, disable it
cpan App::perlbrew

Accessories

Install patchperl and cpanm.

perlbrew install-patchperl
perlbrew install-cpanm

Add a new perl install

Do this in a screen session. It is a long-running process that you won't want interrupted by connectivity problems.

perlbrew install -D useshrplib -D usesitecustomize --as $your_install_name stable
  • The --as switch is optional. Omitting it causes the version to be used instead of a name when managing.
  • -D useshrplib enables compiling perl in terms of a shared library, libperl.so. Optional, but don't omit it without a good reason.
    • Other -D, -U, -A defines are passed the same way.
    • --thread, --multi can also be passed here.
  • -D usesitecustomize enables having this perl automatically run a pre-script, $Config{siteperl}/sitecustomize.pl, before nearly anything else. See -f in perlrun.
    • --sitecustomize filename does this and will also install the given file as sitecustomize.pl.
  • The stable specifier may be replaced with any version number or blead.
    • It can also be replaced with the fully qualified path or URL of a .tar.gz (or .tar.bz2, etc.) archive of a Perl distribution. If the archive is in the current directory, use e.g. "`pwd`"/perl-x.x.x.tar.gz rather than ./perl-x.x.x.tar.gz; otherwise, it won't be recognized.
    • It can also be replaced with the path to a git checkout of the perl code.
  • Other options are available.

This is a full perl install process and will take a substantial about of time. You will be given a tail -f command to follow the log if desired.

I believe it is supposed to work to install the same version twice as long as the names are different. However, there can be only one build directory per version, so don't try to perform the actual installs simultaneously; wait for one to finish before starting the next.

Making the install INSTALL_BASE-friendly (or: extra @INC paths)

When using the INSTALL_BASE parameter on perl module installation (in particular, for modules installed outside cpan such as the Image::Magick example), the installer wants to install stuff in, among other paths,

$INSTALL_BASE/lib/perl5
$INSTALL_BASE/lib/perl5/architecture

Unfortunately, these aren't in the default @INC because the simplified install dirs scheme is used (see INSTALL, Installation Directories, scan for "slightly simplified").

Symlink to a directory already in @INC

If the perl has already been compiled, it should work to use a symlink from the current version number to perl5 before trying to install anything:

cd ~/perl5/perlbrew/perls/installname/lib
ln -s site_perl/5.*.* perl5
# or ln -s 5.*.* perl5

This approach seems sane and simple enough that it's probably the one I'm going to use.

Add to @INC using site customization

If the perl was compiled with usesitecustomize, @INC manipulations can be made directly to lib/site_perl/sitecustomize.pl.

The potential utility of something like this warrants always compiling with this option.

Add to @INC when compiling

If the perl hasn't been compiled yet, you might consider a compile-time mechanism like -Dotherlibdirs to add paths to @INC.

Remove an install

perlbrew uninstall $your_install_name

Simple.

Using on Cygwin

Tricky, and so far I haven't succeeded. Points to note:

Version

5.18.2

PATH

Before attempting to build, ensure PATH contains no spaces or parentheses in order to prevent a shell syntax problem. On Cygwin, this appears to generally mean cutting out all components containing "cygdrive".

cd to build dir

On the first failure, cd into the path perlbrew says to use for installing without tests.

Fix for nostdio.h hack

The only actual build issue is given as a syntax issue at nostdio.h. nostdio.h is a set of hacks designed to prevent subsequent includes of stdio.h by making all usages thereof errors.

One of the hacks used around line 25 causes some choking:

#define FILE struct _FILE

It is mentioned elsewhere that defining PERLIO_NOT_STDIO to 0 in cygwin.h near the beginning temporarily disables the hack in one problematic place.

#define PERLIO_NOT_STDIO 0

Continue build

Do make here. The build should succeed.

Do make test if you like. Some test problems are apparently unavoidable.

Fixes for build failures

cwd.t linktest

When building 5.18.2, I got this failure:

#   Failed test at t/cwd.t line 209.
#                   '/home/username/perl5/perlbrew/build/perl-5.18.2/dist/Cwd/t/linktest'
#     doesn't match '(?^i:\/home\/username\/perl5\/perlbrew\/build\/perl\-5\.18\.2\/dist\/Cwd\/t\/_ptrslt_\/_path_\/_to_\/_a_\/_dir_$)'

A corresponding error reported by someone else said that this manual hack on Cwd.pm got the issue out of the way without forcing the install. Here's my version:

Unpack the perl archive into a temp dir, make the correction, repack it, and install it.

tar xjvf ~/perl5/perlbrew/dists/perl-5.18.2.tar.bz2 
vim perl-5.18.2/dist/Cwd/Cwd.pm # and make the edit
tar czvf perl-5.18.2.tar.gz
perlbrew install --as $somename "`pwd`"/perl-5.18.2.tar.gz

The correction is thus (the ADD line):

# Line 579:
        unless (opendir(PARENT, $dotdots))
        {
            # probably a permissions issue.  Try the native command.
            require File::Spec;
            $start = readlink($start) if -l $start; # ADD this line to resolve a symlink
            return File::Spec->rel2abs( $start, _backtick_pwd() );
        }

This fix seems to have worked.

Image::Magick

One process that is claimed to work for installing Image::Magick is given on perltricks.com.

The given process has a new IM library installed under ~/local. I've changed it to ~/opt/ImageMagick-VERSION-NAME to make it possible to install a different instance per perl install. I've also specified a font path.

IM=ImageMagick-6.8.9-0
IM_DOWNLOADS="http://www.imagemagick.org/download"
OPT="$HOME/opt"
FONT_PATH="$HOME/.fonts"
PB_NAME="perlbrew install name"
PB_DIR="$PERLBREW_ROOT/perls/$PB_NAME"
PB_PERL="$PB_DIR/bin/perl"
PB_CORE="`echo "$PB_DIR"/lib/5.*.*/*/CORE`"
PREFIX="$OPT/$IM-$PB_NAME"
 
WITHOUT_THREADS=`"$PB_PERL" -MConfig -E '$Config{useithreads} or say "--without-threads"'`
ENABLE_SHARED=`"$PB_PERL" -MConfig -E '$Config{useshrplib} eq "true" and say "--enable-shared"'`
unset PERL5LIB
echo Current PERL5LIB: "$PERL5LIB"

CONFIGURE="LDFLAGS=-L'$PB_CORE' \
	./configure $WITHOUT_THREADS $ENABLE_SHARED \
		--prefix '$PREFIX' \
		--with-perl='$PB_PERL' \
		--with-perl-options=INSTALL_BASE='$PB_DIR' \
		--with-fontpath='$FONT_PATH' \
		--with-rsvg"

echo Our configure command looks like:
echo "$CONFIGURE"
read -p "Press enter if this looks right." &&
wget "$IM_DOWNLOADS/$IM.tar.xz" &&
tar xJvf "$IM.tar.xz" &&
cd "$IM" &&
eval "$CONFIGURE" &&
read -p "Press enter to make and install." &&
make install

If retrying any step after the configure without rerunning the script, at least make sure PERL5LIB is unset. Otherwise, the install will attempt to bring in perl stuff from the system perl, and dumb errors like undefined symbol: Perl_Istack_sp_ptr will ruin your day.

To verify the install, the article suggests running the perl and requesting a way-too-high version of the module Image::Magick::Q16 (at least, as of this version if IM, that's where the version information actually is).

$ ~/perl5/perlbrew/perls/installname/bin/perl -MImage::Magick::Q16\ 999
Image::Magick::Q16 version 999 required--this is only version 6.89.
BEGIN failed--compilation aborted.

If the error is about the version and not about the module seeming installed, you're good.

LWP::Protocol::https

No special treatment needed, but see #Net::SSLeay if you need to use a non-system OpenSSL build.

Net::SSLeay

The shared hosting provider may have omitted the OpenSSL dev headers from the system, requiring you to build your own OpenSSL. When this happens, Net::SSLeay won't install properly unless you specify the path as OPENSSL_PREFIX.

Note that this refers to the same dir as the PREFIX from the OpenSSL install. (For example, the file $OPENSSL_PREFIX/include/openssl/x509.h should exist.)

# I installed OpenSSL to its own subdir of ~/opt
OPENSSL_PREFIX=/home/someuser/opt/openssl-1.0.1k cpanm Net::SSLeay

(This problem isn't specific to perlbrew, but the system perl usually already has a working Net::SSLeay.)