gugod / App-perlbrew

Manage perl installations in your $HOME
https://perlbrew.pl
Other
719 stars 216 forks source link

perlbrew switch path order not permanent on MacOS Big Sur 11.4 #727

Closed jblaty closed 3 years ago

jblaty commented 3 years ago

I'm writing a step-by-step instruction guide to installing perlbrew on a newly built (from ISO) MacOS Big Sur (11.4) VM running on VMware Fusion.

I have been able to successfully install perlbrew. Here is what perlbrew info looks like:

perlbrew info

Current perl: Using system perl. Shebang: #!/usr/bin/perl

perlbrew: version: 0.92 ENV: PERLBREW_ROOT: /Users/jblaty/perl5/perlbrew PERLBREW_HOME: /Users/jblaty/.perlbrew PERLBREW_PATH: /Users/jblaty/perl5/perlbrew/bin PERLBREW_MANPATH:

...Great! Now:

perlbrew switch perl-5.32.1 perlbrew info

Current perl: Name: perl-5.32.1 Path: /Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/bin/perl Config: -de -Dprefix=/Users/jblaty/perl5/perlbrew/perls/perl-5.32.1 -Aeval:scriptdir=/Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/bin Compiled at: Jun 23 2021 14:43:45

perlbrew: version: 0.92 ENV: PERLBREW_ROOT: /Users/jblaty/perl5/perlbrew PERLBREW_HOME: /Users/jblaty/.perlbrew PERLBREW_PATH: /Users/jblaty/perl5/perlbrew/bin:/Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/bin PERLBREW_MANPATH: /Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/man

...I'm now running the perlbrew version of Perl. Here is what the path looks like now that I've switched...

print $PATH

/Users/jblaty/perl5/perlbrew/bin:/Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

AWESOME! So in the path, MacOS finds the perlbrew version before the system version of Perl. Everything looks great so far, but I expect that a perlbrew switch to be persistent to each new terminal session I start. Keep in mind that I'm using zsh, and my .zshenv looks like this:

cat .zshenv

source ~/perl5/perlbrew/etc/bashrc

If I close that terminal session and open a new one, and then do another perlbrew info, here's what I get:

perlbrew info

Current perl: Name: perl-5.32.1 Path: /Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/bin/perl Config: -de -Dprefix=/Users/jblaty/perl5/perlbrew/perls/perl-5.32.1 -Aeval:scriptdir=/Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/bin Compiled at: Jun 23 2021 14:43:45

perlbrew: version: 0.92 ENV: PERLBREW_ROOT: /Users/jblaty/perl5/perlbrew PERLBREW_HOME: /Users/jblaty/.perlbrew PERLBREW_PATH: /Users/jblaty/perl5/perlbrew/bin:/Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/bin PERLBREW_MANPATH: /Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/man

...everything looks just fine, right? However, if I have another look at the path:

print $PATH

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/jblaty/perl5/perlbrew/bin:/Users/jblaty/perl5/perlbrew/perls/perl-5.32.1/bin

...WRONG! The perlbrew bin directories are appended to the end of the path, not the beginning as it was before I closed the terminal session, earlier.

Can anyone guide me as to:

  1. What did I do wrong? Did I miss something in the install?
  2. How do I fix perlbrew so the perlbrew bin paths gets prepended to the system paths in subsequent new terminal sessions?
gugod commented 3 years ago

I think this has something to do with the system-wide zprofile at /etc/zprofile, which contains these 3 lines:

# system-wide environment settings for zsh(1)
if [ -x /usr/libexec/path_helper ]; then
        eval `/usr/libexec/path_helper -s`
fi

That path_helper re-order the elements in $PATH however it wants and that appears to be arranging system-y paths such as /usr/local/bin and /usr/bin to the beginning.

I believe this is macOS-specific, but I wonder if other Linux distro comes with something similar by default.

Perhaps instead of ~/.zshenv, try adding source ~/perl5/perlbrew/etc/bashrc to the end of ~/.zshrc or ~/.zprofile -- according to man zsh, those 2 ares read after /etc/zprofile. Basically just let perlbrew rc code tweak PATH after path_helper.

OTOH the currenct on-screen instruction still mentions ~/.zshrc and should be updated, at least when it is on macOS.

jblaty commented 3 years ago

@gugod THANK YOU! This works! I will update my instructions accordingly.

jblaty commented 3 years ago

@gugod THANK YOU! This works! I will update my instructions accordingly.

sdondley commented 3 years ago

I ran into the same problem. Should be documented somewhere besides here, though. I'm new to zsh and only luckily found this issue buried in the "closed" queue.