Skip to content

Instantly share code, notes, and snippets.

@briang
Last active September 15, 2022 09:29
Show Gist options
  • Save briang/73a3e1ad81059ecaee5a800368a1eadb to your computer and use it in GitHub Desktop.
Save briang/73a3e1ad81059ecaee5a800368a1eadb to your computer and use it in GitHub Desktop.
A shared perlbrew root for multiple users (perlbrew in /opt)

A shared perlbrew root for multiple users

作者:gugod 發佈於:2010/12/07 https://gugod.org/2010/12/a-shared-perlbrew-root-for-multiple-users/

Perhaps the biggest advantage of using perlbrew 0.15, is the possibility to share one perlbrew root among multiple users, assuming everyone uses bash (or zsh, which is compatible to bash.)

Let's assume the following scenario:

  • the global perlbrew is located at /opt/perlbrew
  • a user named perlbrew has write permission, and can install new perls and modules
  • all other users have read-only access

First of all, the perlbrew user should set PERLBREW_ROOT before installing perlbrew:

export PERLBREW_ROOT=/opt/perlbrew
curl -L http://xrl.us/perlbrewinstall | bash
/opt/perlbrew/bin/perlbrew init

The perlbrew executable is then installed as /opt/perlbrew/bin/perlbrew. The init command is required at this moment but it has be working to be automatically invoked when necessary. After this, everyone else in the system can simply add these two lines to their ~/.bashrc to use perlbrew:

export PERLBREW_ROOT=/opt/perlbrew
source $PERLBREW_ROOT/etc/bashrc
source $PERLBREW_ROOT/etc/perlbrew-completion.bash

Each user now has a personal init file at ~/.perlbrew/init, which is auto-generated to store the result of perlbrew switch. Not using symlink anymore so there is no permission problem in the way. As long as users have read and exec permissions to some PERLBREW_ROOT, they can invoke perlbrew exec, perlbrew use and perlbrew switch just fine. /opt/perlbrew can simply be managed by the root user, no big deal. If you do not mind, you can share your $HOME/perl5/perlbrew with others too.

This seems to be a pretty handy outcome of ditching the symlink approach. It might not be needed by many people. However when someone needs it, I hope it will be simple enough for them to do what they want.

@briang
Copy link
Author

briang commented Sep 15, 2022

In case there's any doubt:

I AM NOT THE ORIGINAL AUTHOR OF THIS DOCUMENT

That would be Gugod, in a blogpost from 2010 (linked above).

I've made a couple of edits to his original, mostly for grammar. I also added the line that sources perlbrew-completion.bash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment