Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

SOLVED: Funny Little Permissions Issue on Ubuntu

by BJ_Covert_Action (Beadle)
on Apr 22, 2009 at 09:57 UTC ( #759227=perlquestion: print w/replies, xml ) Need Help??

BJ_Covert_Action has asked for the wisdom of the Perl Monks concerning the following question:

Howdy All, I have been working for a few hours now on getting some stuff configured on my home box which is running Ubuntu 8.04 right now. Basically, I have troubleshot a lot of the problems down to this:

I typically use the CPAN.pm shell to install any modules I need/want/so eagerly desire from the CPAN. In order to get a successful make test and install, I usually have to access the CPAN shell via the root account. I have been doing so by using:

sudo perl -MCPAN -e shell

Once in the CPAN shell I go through the entire get, make, test, and install command set with whatever perl module I want (this time I was trying to get Pod::Simple downloaded). Interestingly enough, the install seems to work without a hitch as I would hope. However, when I then exit the CPAN shell I test to ensure that the new module is, indeed, accessible to me via:

sudo perl -MPod::Simple

...at which point I am consistently notified that the module does not exist in my @INC variable which includes:

/etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .

I started reviewing my CPAN module install command output and found that my modules were actually installing to: /root/perl. Which, as you can see, is not in my @INC variable. So I have been digging now for a couple hours for a workaround and have come up dry.

Ideas I have had for fixing this bug were:

1) Reconfigure my CPAN module to install to a different directory

2) Reconfigure my @INC variable to contain the /root/perl directory (could cause permission issues?)

3) Install modules with the CPAN shell not as root (tried this, almost always results in a permissions error)

So I am kind of at an impasse. I looked for info on how to do 1 or 2, but couldn't find anything solid. I did try adding /root/perl to my /etc/profile file PERLLIB variable (yes, I included the export command) and nothing seemed to happen. Any ideas?

Thanks for all help ahead of time,

Brady

Replies are listed 'Best First'.
Re: Funny Little Permissions Issue on Ubuntu
by Lu. (Hermit) on Apr 22, 2009 at 10:51 UTC
    Is this perl the system perl ? (the one that came with ubuntu)

    If that's the case, you'd be better off using option number 4 : using apt-get to install perl modules. Most of them are accessible from the repositories. Or you could use some utility, like cpan2deb, which will convert cpan packages to .deb installable archives. One advantage is that you will never have test failures during installation.

    Or use option 5, which is installing or compiling your own perl, in a directory where you have write access (for example, I use /opt/ as the prefix, and executables in /opt/bin, modules under /opt/lib ...)

    Option 2 will cause permission issues, because you don't have access to subdirectories of the /root directory. No read, no write, no nothing.

    Option 3 too, because you don't have write access in /usr/local/whatsitsname and you don't want to have it (security issues ahead).

    So, my advice is : use synaptic to install your modules, or install your own perl. Don't mess with system perl.

    Lu.
Re: Funny Little Permissions Issue on Ubuntu
by przemo (Scribe) on Apr 22, 2009 at 10:58 UTC

    You didn't mention clearly, why do you install modules as a root. Is it a multi-user environment, or you are the only citizen in the system?

    If you want installed modules to be seen by other users, the best place for them is /usr/local. And this should be the default setting on fresh run of CPAN -- unless in my case (Ubuntu 9.04). Either run 'o conf init' from inside CPAN shell, or remove ~/.cpan dir to start from the beginning.

    If you want to install modules for yourself only, I'd recommend using local user's folder -- this is the way I work and had no problems with it yet. To do so:

    1. Create folder ~/perl
    2. set PERL5LIB=~/perl/lib/perl5 somewhere in startup script (e.g. ~/.bash_profile)
    3. set following options in the CPAN
      o conf makepl_arg INSTALL_BASE=~/perl o conf mbuildpl_arg "--install_base ~/perl"

    (in above code ~ is your homedir, please expand it)

    After that, the CPAN installation should place all files in ~/perl.

Re: Funny Little Permissions Issue on Ubuntu
by parv (Vicar) on Apr 22, 2009 at 10:42 UTC

    You may have to remove|edit any existing CPAN configuration lying around which causes the cpan shell to install things under /root/perl. Specifics would be provided by those who have used cpan more extensively.

    If you are installing things on system wide basis, then for all practical purposes do not install in /root or include /root in @INC.

    Do you see /root/perl in @INC when you run perl as mere mortal, after fiddling with PERLLIB? Does your shell suppose to source /etc/profile (bash & zsh do; could not find it in tcsh man page)?

    BTW, your @INC seems to be missing architecture specific directories. Did you change install settings to not to create, or install in, those directories?

      BTW, your @INC seems to be missing architecture specific directories.

      That's the way Debian does it, and hence Ubuntu does it that way too.

        Thanks for the explanation. (I would need to look further if|how I could get rid of architecture specific directories myself when I am installing in my own space on CentOS 5 & FreeBSD 6|7.)
Re: Funny Little Permissions Issue on Ubuntu
by moritz (Cardinal) on Apr 22, 2009 at 11:21 UTC
    While it's not an answer to your question, I want to tell you that many CPAN modules are actually packaged for Ubuntu already, for example the Pod::Simple in your example is in libpod-simple-perl.

    With the program dh-make-perl you can also turn cpan packages into .deb packages.

Re: Funny Little Permissions Issue on Ubuntu
by BJ_Covert_Action (Beadle) on Apr 22, 2009 at 15:50 UTC
    I am using the bash shell so it should be sourcing /etc/profile so far as I know. No, I do not see /root/perl in @INC whether I run as root or as my own account (even after fiddling with PERLLIB).

    I am the only user on my system (nobody else accesses my computer), but I install modules as root typically because if I don't enter the CPAN shell as root, the installs fail due to permission restrictions (for some reason my unzipped packages that are downloaded with get end up locked to my user account about half the time.

    I have been using the system perl that came with ubuntu because I figured that it was adequate and easy enough to interface (oddly enough I am finding it easier to interface with my strawberry distribution at work on Windows). I would be interested in installing and configuring my own perl distribution in another folder, except then I would be worried about perl version conflicts and what not (I don't know what kind of complications come with having two different perl builds on one machine, if someone could point me to some info on this it might be my best option).

    Installing modules via synaptic is not a terrible idea either, I didn't realize modules were apt-getable because they are named with the lib prefix. Does anyone know if synaptic provides access to all CPAN modules, or just certain ones?

    I think I might try reconfiguring CPAN in the manner przemo mentioned above when I get home. If that works I will probably keep working in the local directory (which is where I would like to work, but CPAN somehow got configured to install in /root/perl instead. przemo, I do have a question, when you say, "set the following options in the CPAN, is that code I should be adding/tweaking in CPAN.pm, or is there some other configuration file/setting I need to mess with? I wasn't aware of the 'o config init' command (which they just happen to leave out of the help option inside the shell), so I will see where that takes me after work today and keep you all posted.

    Thank you all for the suggestions so far.

      ...except then I would be worried about perl version conflicts and what not

      When you adhere to a few basic rules, there are no conflicts to be expected.

      Essentially, those rules are:

      • Always take care to call the perl binary belonging to the version you want to use. I.e. put #!/usr/local/bin/perl in your shebang line if you want to use your own (non-system) Perl and that's the location where you've installed it to.  Similarly, if you want to get that same version when you type perl on the command line (without path), make sure it's found first along your PATH.  (If you want to use another version, you can always type the absolute path, e.g. /usr/bin/perl to get the system Perl.)

      • Don't mess with PERL5LIB on a global level (like in /etc/profile, or some such).  If you really need to fiddle with it, do it locally, i.e. in a specific shell environment, via a wrapper, or by prefixing a command line like so: PERL5LIB=/whatever/dir your-command-here

      Every perl binary by default 'knows' where its modules are located (when once correctly set up), so it will find existing modules in, or install new modules to exactly those locations.

      Personally, I have at least 2 to 3 Perl versions on all my machines, and I've never had any conflicts due to this. Quite the contrary, certainly less potential conflicts than when messing with the Perl that comes with the system...  The only downside is that you sometimes have to install the same modules several times.

      As to using only the pre-built deb packages provided by the distro together with the system Perl, I'd say that's in principle fine, as long as you don't always want the latest and greatest. Virtually all commonly used modules are available, but not always in the most recent version...  OTOH, that's the easiest way, because nothing needs to be built, which is particularly nice with modules that aren't trivial to build, as for example when they depend on various C libs which itself depend on other libs that must be the correct versions, etc.

      No, I do not see /root/perl in @INC whether I run as root or as my own account (even after fiddling with PERLLIB).

      Do you mean that the following two commands give the same results in respect to @INC? They shouldn't.

      $ PERL5LIB= perl -V $ PERL5LIB=/home/me/perl/lib/perl5 perl -V
      when you say, "set the following options in the CPAN", is that code I should be adding/tweaking in CPAN.pm, or is there some other configuration file/setting I need to mess with?

      Those were the commands to put at CPAN's shell prompt. I forgot to mention that you should issue o conf commit after that, but cpan should inform you about that.

      Alternatively, you can modify settings directly in ~/.cpan/CPAN/MyConfig.pm. It's safe as long as you just play with it as a casual user. This is a big plus in this approach: when experimenting with local installation dir, if you break something, just remove destination folder (~/perl in my example) and ~/.cpan and you have clean environment. You loose all your settings, but hey, this is how experimenting works. :)

      Good luck!

        Well I managed to get the issue ironed out by adding some lines into the MyConfig.pm. I gleaned the syntax from reading what was already there and using the variables you mentioned setting inside the CPAN shell. I would post more details but I am not on the same machine right now for reference.

        I think I might try working with a second perl distribution when I get around to it as well, it would be good to learn how to do that.

        Thanks for the help so far, I will try to post details of what I changed later in case any other users want to look at this thread for help/reference.

        Cheers.

        P.S. Regarding the @INC output, I will address that when I get home, I haven't run both of those commands to know.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://759227]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2019-11-15 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (85 votes). Check out past polls.

    Notices?