in reply to Re: How to install Perl modules locally on Unix?
in thread How to install Perl modules locally on Unix?

Thank you for the suggestions and instructions. I was able to install local::lib in my home directory, but don't have cpanm and though I tried to install it with cpan install I still can't get it to run.

-bash: cpanm: command not found

Replies are listed 'Best First'.
Re^3: How to install Perl modules locally on Unix?
by haukex (Archbishop) on Nov 28, 2017 at 08:52 UTC
    I was able to install local::lib in my home directory,

    Did you set up the environment variables as described in the local::lib docs? For example, for bash, the docs suggest: echo 'eval "$(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)"' >>~/.bashrc

    Note that you have to log out and log back in once for this to take effect.

    but don't have cpanm

    Did you try the installation command I showed from the App::cpanminus docs (after setting up the environment vars)? That is: curl -L https://cpanmin.us | perl - App::cpanminus

      Ok I was able to get it working by running the EXPORT commands from the command line. I'll work with my service provider to figure out how to automate that.

      Thanks so much for your help, I'm up and running!

      Scott

        Sorry for the late reply, I've been busy. I'm glad to help!

        I'll work with my service provider to figure out how to automate that.

        Depending on where you want the new library path to take effect, the ways to best do that differ:

        If it's the shell, then as choroba pointed out, maybe you are using a shell other than bash and that shell uses a different initialization script into which you need to put the PERL5LIB etc. variable definitions. Try the command echo $SHELL to find out which shell it is <update> is the default shell, which may be different from the currently running shell (thanks for pointing this out, choroba) - you might try a command like pstree $$ to help figure out the currently running shell. </update>

        If it's for the CGI scripts, then note that web servers will usually provide their own, quite restricted, environment to CGI scripts. There are several ways to go about telling the CGI script to look in your home directory for modules, but in my experience, if this script is running on a single provider and the directory structure is unlikely to change, using lib from within the CGI script is often easiest. Usually that'll look something like use lib '/home/yourusername/perl5/lib/perl5'; - try echo $HOME in the shell to find out your home directory location. Also note that the web server needs permissions to access that directory (generally 755 for directories and 644 for files), since the web server will likely be running under a different username, such as nobody.

      Hi, yes I did add that line to .bashrc and ran the curl command - still not able to run cpanm.

      Thanks for helping.

        Maybe it needs to be read?

        After writing your shell configuration file, be sure to re-read it to get the changed settings into your current shell's environment. Bourne shells use . ~/.bashrc for this, whereas C shells use source ~/.cshrc.
        I did add that line to .bashrc

        What do you mean by "that line"? Note that you should run the echo 'eval... command I showed at the command line, and not add that line to .bashrc. If you did run that command, you should be able to look at your .bashrc with something like tail ~/.bashrc, and at the end of the file, see several variable definitions like PATH=..., PERL5LIB=..., and PERL_.... If you don't see those, then perhaps something went wrong with the echo 'eval ...' >>~/.bashrc command.

        If you do see those variables, and you've logged out and back in again, you should be able to do echo $PATH and somewhere in the output find something similar to /home/yourusername/perl5/bin, and if you do echo $PERL5LIB, see a path perl5/lib/perl5 below your home directory. If you can see those things, then at the moment I don't see why the command to install cpanm should fail - did you get any error messages? If you could show (inside <code>) tags the exact commands you tried and the output you got (including the output of the commands I showed here, like echo $PATH), that would be helpful.