when using CPAN in linux ubuntu should I run it using sudo / as root or as my default user

You should run the cpan command as your normal user. You have two choices:

  1. Install modules into a directory under your home dir. local::lib will help you set that up.

  2. Configure cpan to use sudo during the install phase. You do that by starting the cpan shell and typing:

    o conf make_install_make_command 'sudo make'
    o conf mbuild_install_build_command 'sudo ./Build'
    o conf commit
    

    The first line configures MakeMaker to use sudo. The second line does the same for Module::Build. The third line saves the changes.


If you want to install your modules for your own use, then you should be running it as yourself. Use local::lib to set up your environment variables so that this works nicely. You may wish to look at cpan minus as an alternative to the default cpan installer.

You may also wish to consider using perlbrew to install a newer version of perl that is completely independent from the system perl.

If you want to install them system wide, then I recommend (since you have tagged this ubuntu) looking at dh-make-perl to produce .deb files that you can install and uninstall with dpkg.


If you want to install modules as a non-root user, you can configure your cpan to use an install base:

makepl_arg         [INSTALL_BASE=/home/nelaar/perl]
mbuildpl_arg       [--install_base=/home/nelaar/perl]

And set PERL5LIB accordingly to /home/nelaar/perl/lib/perl5.