Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: @INC error

by haukex (Archbishop)
on Jan 18, 2020 at 20:54 UTC ( [id://11111587]=note: print w/replies, xml ) Need Help??


in reply to Re^2: @INC error
in thread @INC error

My question now is how can I remove all versions of Perl and start with a completely new version including the necessary additions to @INC?

Well, you don't necessarily need to remove the old versions to build a fresh, self-contained Perl. In any case, you first need to hunt down and eliminate all environment variables related to Perl. In particular, look in your ~/.profile and ~/.bashrc, but environment variables could also be set elsewhere (like some files under /etc, depending on the system). Look for anything Perl-related, including for example source ~/perl5/perlbrew/etc/bashrc. Those would be in particular PERL5LIB, any PATH entries pointing to any specific Perl builds, PERL_MB_OPT, PERL_MM_OPT, PERL5OPT, and really any other environment variables with PERL in the name (see perlrun). If you're unsure about any of these, feel free to ask here.

Then, it depends on whether it's enough to install Perl in your home directory, or whether you want to install it in some system-wide location. For the former, I'd suggest perlbrew. You can clobber ~/perl5/perlbrew/ first if you want to make sure you're getting a fresh start. Of course, if the file permissions on ~/perl5/perlbrew/ allow it, then you can use this Perl on the entire system.

If you wanted to build Perl from source into some global location, like say /opt, then have a look at the INSTALL file. In short, it can be as simple as doing the following in the Perl source directory: sh Configure -de -Dprefix='/opt/perl5.30' && make && make test && sudo make install.

Both of the methods above will set up self-contained Perl builds, that is, their @INC directories will only be located below ~/perl5/perlbrew/perls/perl-*/ or /opt/perl5.30, respectively, instead of being spread out all over the system. You can freely install modules there, and you no longer need to worry about @INC, PERL5LIB, local::lib, and so on. You only need to worry about your PATH pointing to the installation of Perl you want to use, or pointing your shebang line at the correct Perl.

For installing modules, I strongly recommend cpanm, which you can install via curl -L https://cpanmin.us | perl - App::cpanminus (see App::cpanminus). When you're installing modules, you can check which perl and which cpanm to make sure they are from the same installation, otherwise you've got something strange going on with your PATH.

If the installation gets mucked up somehow, you can simply perlbrew uninstall or rm -rf /opt/perl5.30 to clobber them. Keeping a cpanfile with your dependencies is an advantage, since it allows easy re-installation of your modules with "cpanm --installdeps .".

Then, in your crontab file, make sure to call the correct Perl, I recommend doing this with the absolute pathname. So for example, 0 0 * * *  /opt/perl5.30/bin/perl /home/user/script.pl arg1 arg2 ....

Replies are listed 'Best First'.
Re^4: @INC error
by syphilis (Archbishop) on Jan 19, 2020 at 00:28 UTC
    sh Configure -de -Dprefix='/opt/perl5.30' && make && make test && sudo make install

    Just to point out (to worstead) that one can do the same thing to install perl into one's home directory, without any need for perlbrew to be involved:
    sh Configure -de -Dprefix=/home/me/perl530 && make && make test && mak +e install
    Not that I'm suggesting that you should avoid perlbrew. It's widely used and generally recommended - from which I deduce that it's reliable and user-friendly.
    (I've never even looked at it, so I don't know.)

    Cheers,
    Rob
      Not that I'm suggesting that you should avoid perlbrew. It's widely used and generally recommended - from which I deduce that it's reliable and user-friendly. (I've never even looked at it, so I don't know.)

      Probably its main advantage is that it makes switching between Perl installations easy; it takes over modifying PATH etc. so that you can switch between the system Perl and the Perlbrew installed Perls either for the current session or for all future sessions easily. It also can make use of Devel::PatchPerl (especially useful for installing older Perls), and has a command that installs cpanm. But as you said, doing a manual install into one's home directory is fine too of course.

        Probably its main advantage is that it makes switching between Perl installations easy

        That can also be easily accommodated with shell or batch scripts. (I guess that's just a homespun, poor person's Perlbrew ;-)
        In any case, I don't find it a great hassle to run export PATH=~/blead-5.31.7/bin:$PATH

        There are, however, traps for the unwary in simply pre-pending another perl to the path.
        For example, what happens when you then run cpan -i Some::Module and the first perl in the path doesn't have a 'cpan' utility (because it's named 'cpan5.31.7') but the next perl in the path does have a utility named 'cpan' ?

        IIRC, I eventually learned that I should always build blead with '-Uversiononly'. That way, the cpan utility will be named 'cpan'.
        (The same issue also existed wrt other utilities if '-Uversiononly' was omitted.)

        On Windows, when I switch to a different version of perl, I generally need to switch to a different version of gcc (also handled by the same batch script).
        This is because, on Windows (for me, at least), each build of perl has a runtime dependency upon the gcc installation that built it.
        Perl versions 5.8.8 through to 5.18.0 were built with gcc-4.7.0, followed by others built using gcc-4.8.2, gcc-5.3.0, gcc-6.3.0 or gcc-8.1.0.
        Therefore, switching to another version of perl can often necessitate switching to another version of gcc.
        I'm not sure that, even if Perlbrew had built these perls, it could handle the required switching of compilers ??
        Come to think about it, I don't actually know if Perlbrew can be used to build perl on Windows at all. (I suspect not.)

        Cheers,
        Rob
Re^4: @INC error
by worstead (Acolyte) on Jan 20, 2020 at 20:25 UTC
    Removed most of my old versions of perl but cannot download perlbrew. There appears to be no simple download site. Have tried the following:
    wget -O - https://install.perlbrew.pl | bash
    and
    curl -L https://install.perlbrew.pl | bash
    In each case get
    Need /usr/bin/perl or /usr/local/bin/perl to use bash
    which I do not now have.

      Sorry, should have been more clear on this: you'll need at least one Perl to bootstrap the others with, that's usually the system Perl, so reinstall that using your system's package manager. The advantage of the methods I described is that they don't touch the system Perl.

        Things get worse. I supposedly installed perl using "dnf install perl" in Fedora 31, which seemed to work OK. However, I now have no command "perl" in any of my "bin"s and no paths in @INC. I looked for a simple perl tarball, like I used many years ago, but can't find one, only "ActivePerl-5.28.1.0000-x86_64-linux-glibc-2.12-f7fd6fde.tar.gz".
Re^4: @INC error
by worstead (Acolyte) on Jan 20, 2020 at 19:18 UTC
    Appreciate all the directions. Shall attempt in next few days and post result.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found