Perl – CPAN first launching configuration


I'm taking a look into Perl as a total beginner. I want to try some CPAN modules.
When I run an install command on my Osx console, CPAN asks for a configuration with the following statement :

To install modules, you need to configure a local Perl library
directory or escalate your privileges. CPAN can help you by
bootstrapping the local::lib module or by configuring itself to use
'sudo' (if available). You may also resolve this problem manually if
you need to customize your setup.

What approach do you want? (Choose 'local::lib', 'sudo' or 'manual')

What is the difference between local::lib and sudo options ?
If I understand it well, it installs some modules locally on my computer. But I don't see any difference between the two config above.

Best Solution

If you use sudo, CPAN will use root to install the libraries in a central location where all users on the machine can access the files without any special configuration. If you use 'local::lib', it will create a library in your home directory and install the modules such that only perl programs that have been configured to look for modules in your home directory will find the modules.

Perl uses the special variable @INC to search for module paths. So you can install modules anywhere as long as you set @INC properly before you use them. This article explains the basics.

You can do all kinds of fun stuff with @INC; one of my favorite hacks it to put a function pointer in there and use custom perl code to lookup modules.

Related Question