I can't tell that the following is the answer for the I want to finally, once and for all, learn the proper way... , but this is how me doing it in all my deployments.
- Install anyenv
sudo git clone https://github.com/riywo/anyenv /opt/anyenv
- you could deploy it into your $HOME
as git clone https://github.com/riywo/anyenv ~/.anyenv
but myself prefering some commonly accessible place. This step isn't mandatory, but for me help managing other local installations as node
and such.
- change ownership:
sudo chown -R jm666 /opt/anyenv
- you will manage the content
- add into the
.profile
:
export ANYENV_ROOT=/opt/anyenv
export PATH="$ANYENV_ROOT/bin:$PATH"
eval "$(anyenv init -)"
Relog, or run exec $SHELL -l
. Now you have installed an helper for all commonly needed environments.
Now install the perl
env. helper, called plenv
.
anyenv install plenv
Or follow the guide in the repo if you don't want the previous anyenv
step.
And finally install fresh perl
using plenv
:
plenv install -l #will display all available perl versions
plenv install 5.26.1 -j 8 # number of proc cores or less. :)
This will take some time - on my notebook 4m23,186s - just tested :).
plenv global 5.26.1 # now all `perl script.pl` will use the freshly installed perl
plenv install-cpanm
plenv rehash #needed if you install some commands which should be accesible from `bash`
And you're ready to install any perl modules using cpanm
- without compromising the system-wide installed perl. Everything will be installed into the plenv
's directory tree. Even, you never need be root
.
This way I could manage to have the same development and deployment environment. Maybe here is a better way - but for me the above works.
In short, read: