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

Thank you all for your help. Clearly my Perl installation is a mess. The agility of my memory has deteriorated since I began programming in assembly language in in the 1950s. I have also become lazy. I use Fedora (currently 31) and have relied on upgrading instead of new installations. As a result the various additions and even separate installations of Perl that I have made over the years still exist on my hard drive, I probably went to cpan as a user as well as root. In addition, I have various additions to @INC in .bashrc and /etc/profile whose purpose I have forgotten. Over ten years ago I was installing Perl from a tarball because Fedora did not include PerlMagick.

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? Using "dnf remove" or "rpm -e" will only remove my latest version (i.e. perl-5.30.1-449.fc31.x86_64). As a last resort I could completely reinstall Fedora but that would take a long time considering the number of additional programs I have installed and the tweaks I have made.

Replies are listed 'Best First'.
Re^3: @INC error
by haukex (Archbishop) on Jan 18, 2020 at 20:54 UTC
    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 ....

      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.

      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.

      Appreciate all the directions. Shall attempt in next few days and post result.