如何以非 root 用户身份使用 CPAN? [英] How can I use CPAN as a non-root user?

查看:36
本文介绍了如何以非 root 用户身份使用 CPAN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我没有 root 访问权限的共享服务器上安装 perl 模块.我怎样才能做到这一点?他们似乎也有旧版本的 CPAN(它在运行命令时抱怨),是否可以在不需要 root 访问权限的情况下更新我帐户中正在使用的 CPAN 命令?

I want to install perl modules on a shared server on which I do not have root access. How can I do this? They also seem to have an older version of CPAN (it complains about that when running the command), is it possible to update the CPAN command being used from my account without requiring root access?

推荐答案

目前我找到的最简单的方法就是说

The easiest method I have found so far is to say

wget -O- http://cpanmin.us | perl - -l ~/perl5 App::cpanminus local::lib
eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`
echo 'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`' >> ~/.profile
echo 'export MANPATH=$HOME/perl5/man:$MANPATH' >> ~/.profile

这里假设您的配置文件名为 .profile,您可能需要将其更改为 .bash_profile.bashrc 等.之后您可以通过说

This assumes your profile is named .profile, you may need to change that to be .bash_profile, .bashrc, etc. After that you can install modules by saying

cpanm Module::Name

并像安装在根目录中一样简单地使用它们.

and simply use them the same way you would if the were installed in the root directories.

以下是对上述命令作用的简要说明.

What follows is a brief explanation of what the commands above do.

wget -O- http://cpanmin.us 获取最新版本的 cpanm 并将其打印到 STDOUT 然后通过管道传输perl - -l ~/perl5 App::cpanminus local::lib.第一个 - 告诉 perl 期望程序进入 STDIN,这使得 perl 运行cpanm 我们刚刚下载.perl 将其余参数传递给 cpanm.-l ~/perl5 参数告诉 cpanm 在哪里安装 Perl 模块,另外两个参数是要安装的两个模块.[App::cpanmins]1 是安装 cpanm 的包.local::lib是一个辅助模块,用于管理在本地目录中运行模块所需的环境变量.

wget -O- http://cpanmin.us fetches the latest version of cpanm and prints it to STDOUT which is then piped to perl - -l ~/perl5 App::cpanminus local::lib. The first - tells perl to expect the program to come in on STDIN, this makes perl run the version of cpanm we just downloaded. perl passes the rest of the arguments to cpanm. The -l ~/perl5 argument tells cpanm where to install Perl modules, and the other two arguments are two modules to install. [App::cpanmins]1 is the package that installs cpanm. local::lib is a helper module that manages the environment variables needed to run modules in local directory.

安装这些模块后,我们运行

After those modules are installed we run

eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`

设置使用本地模块所需的环境变量,然后

to set the environment variables needed to use the local modules and then

echo 'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`' >> ~/.profile

以确保我们下次登录时能够使用它们.

to ensure we will be able to use them the next time we log in.

echo 'export MANPATH=$HOME/perl5/man:$MANPATH' >> ~/.profile

希望能让 man 找到本地模块的手册页.

will hopefully cause man to find the man pages for your local modules.

这篇关于如何以非 root 用户身份使用 CPAN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆