Why does installing certain CPAN modules require root privilege?

╄→尐↘猪︶ㄣ 提交于 2019-12-20 16:53:27

问题


I need to install some CPAN modules in a linux box which I do not have the root privilege.

The installation of Spreadsheet::WriteExcel goes quite smoothly. But the try to install File::Find::Rule failed with warning "you do not have permissions to install into ....." and hint "you may have to su to root to install the package"

I'm puzzled why some CPAN module installation require root privilege while there are others do not ? and If I really want to use the File::Find::Rule in that linux box , is there any work-around solution I can choose ?

thanks.


回答1:


Have you setup CPAN for that user to install into a directory you control?

If so, then you could be running in the differences amongst modules that use Extutils::MakeMaker (the oldest and most common build/install system), Module::Build, and Module::Install. They all have little quirks.

This is why local::lib was created. Once you have it installed and setup you shouldn't have to worry about it again (except for rogue modules that want to write things to specific places even though they have been told not to).




回答2:


Check out local::lib for installing to other locations.




回答3:


From perlfaq8:


How do I keep my own module/library directory?

When you build modules, tell Perl where to install the modules.

For Makefile.PL-based distributions, use the INSTALL_BASE option when generating Makefiles:

perl Makefile.PL INSTALL_BASE=/mydir/perl

You can set this in your CPAN.pm configuration so modules automatically install in your private library directory when you use the CPAN.pm shell:

% cpan
cpan> o conf makepl_arg INSTALL_BASE=/mydir/perl
cpan> o conf commit

For Build.PL-based distributions, use the --install_base option:

perl Build.PL --install_base /mydir/perl

You can configure CPAN.pm to automatically use this option too:

% cpan
cpan> o conf mbuild_arg --install_base /mydir/perl
cpan> o conf commit



回答4:


You probably don't have permissions to install your module to a system directory like /usr/lib. If you want to do this, you need to run the make install step with superuser permissions (su or sudo).

Alternatively, you can install a Perl module to a local directory which you have permissions for, rather than installing to the default system location. You specify the custom directory when generating the makefile.

From perlmodinstall:

gzip -dc yourmodule.tar.gz | tar -xof -
perl Makefile.PL PREFIX=/my/perl_directory
make
make test
make install



回答5:


It is true that some packages under UNIX require the user to be "root". When installing Template::Toolkit it triggered AppConfig, which bailed out with:

  You may have to su to root to install the package
  (Or you may want to run something like
    o conf make_install_make_command 'sudo make'
  to raise your permissions.

Cygwin is not UNIX. It is just a set of UNIX utilities for Cygwin. There is no root user and no sudo and no way to fake it. If you run Bash as administrator this has not the effect of somehow becoming root. (Actually it can be dangerous.)

The actual problem was that /usr/man/man3 had no permissions:

 > ls -ls /usr/share/man
total 1.2M
384K d--------- 1 spindlea Domain Users 0 Oct 29 18:55 man1/
768K d--------- 1 spindlea Domain Users 0 Oct 29 18:55 man3/
8.0K d--------- 1 spindlea Domain Users 0 Oct 29 12:35 man5/
 12K d--------- 1 spindlea Domain Users 0 Oct  6 16:26 man7/
 12K d--------- 1 spindlea Domain Users 0 Oct 29 12:35 man8/
   0 d--------- 1 spindlea Domain Users 0 Oct  6 16:26 mann/

So the man-pages could not be installed. Reason: C:/Cygwin was unpacked from an archive. Under NTFS file systems, Cygwin by default implements UNIX permissions on Windows ACLs (although you can't see them in the "Security" tab). These did not survive the ZIP archive.

To restore the permissions use something like:

 > chmod -R 755 /usr/bin        # sets -rwxr-xr-x
 > chmod -R 755 /usr/local/bin  # sets -rwxr-xr-x
 > find /bin  -type d -print -exec chmod 777 {} \;
 > find /etc  -type d -print -exec chmod 777 {} \;
 > find /usr  -type d -print -exec chmod 777 {} \;
     .
     .

Problem gone. The installation went through without problems. CPAN was able to satisfy all dependencies.

No "You may have to su to root to install the package" errors anymore.




回答6:


Possible other answers already on Stackoverflow:

  • How can I install a CPAN module into a local directory?
  • How do I tell CPAN.pm to install all modules in a specific directory?
  • How can I install CPAN modules locally without root access?



回答7:


It's because some packages are installed into locations that your user doesn't have permission to write to.

My recommendation would be to get an admin to install the packages for you. I suspect there isn't a simple way to work around this.



来源:https://stackoverflow.com/questions/1366902/why-does-installing-certain-cpan-modules-require-root-privilege

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!