<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>生信菜鸟团 &#187; local</title>
	<atom:link href="http://www.bio-info-trainee.com/tag/local/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bio-info-trainee.com</link>
	<description>欢迎去论坛biotrainee.com留言参与讨论，或者关注同名微信公众号biotrainee</description>
	<lastBuildDate>Sat, 28 Jun 2025 14:30:13 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.33</generator>
	<item>
		<title>perl模块终极解决方案-上</title>
		<link>http://www.bio-info-trainee.com/1474.html</link>
		<comments>http://www.bio-info-trainee.com/1474.html#comments</comments>
		<pubDate>Tue, 15 Mar 2016 12:03:43 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[local]]></category>
		<category><![CDATA[模块]]></category>
		<category><![CDATA[非root]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=1474</guid>
		<description><![CDATA[不管别人怎么说，反正我是非常喜欢perl语言的！ 也会继续学习，以前写过不少pe &#8230; <a href="http://www.bio-info-trainee.com/1474.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>不管别人怎么说，反正我是非常喜欢perl语言的！</p>
<p>也会继续学习，以前写过不少perl模块的博客，发现有点乱，正好最近看到了关于local::lib这个模块。</p>
<p>居然是用来解决没有root权限的用户安装，perl模块问题的！</p>
<p>首先说一下，如果是root用户，模块其实没有问题，直接用cpan下载器，几乎能解决所有的模块下载安装问题！</p>
<p>但是如果是非root用户，那么就麻烦了，很难用自动的cpan下载器，这样只能下载模块源码，然后编译，但是编译有个问题，很多模块居然是依赖于其它模块的，你的不停地下载其它依赖模块，最后才能解决，特别麻烦</p>
<p>但是，只需要运行下面的代码：<code></code><br />
<code></code></p>
<blockquote>
<pre class=""><code><span class="">wget </span><span class="">-</span><span class="">O</span><span class="">-</span><span class=""> http</span><span class="">:/</span><span class="">/<a href="http://cpanmin.us">cpanmin.us</a> | perl - -l ~/</span><span class="">perl5 </span><span class="">App</span><span class="">::</span><span class="">cpanminus </span><span class="">local</span><span class="">::</span><span class="">lib
</span><span class="">eval</span> <span class="">`perl -I ~/perl5/lib/perl5 -Mlocal::lib`</span><span class="">
echo </span><span class="">'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`'</span> <span class="">&gt;&gt;</span> <span class="">~</span><span class="">/.profile
echo 'export MANPATH=$HOME/</span><span class="">perl5</span><span class="">/</span><span class="">man</span><span class="">:</span><span class="">$MANPATH</span><span class="">' &gt;&gt; ~/.profile</span></code></pre>
</blockquote>
<p>就能拥有一个私人的cpan下载器，<code><span class="">~/.profile可能需要更改为<span style="color: #ff00ff;">.bash_profile, .bashrc, etc</span>等等，取决于你的linux系统！<br />
</span></code></p>
<p>然后你直接运行<code><span class="">cpanm </span><span class="">Module</span><span class="">::</span><span class="">Name，就跟root用户一样的可以下载模块啦！<br />
</span></code></p>
<p>或者用下面的方式在shell里面安装模块，其中ext是模块的安装目录，可以修改</p>
<blockquote><p> perl -MTime::HiRes -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext Time::HiRes;<br />
perl -MFile::Path -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext File::Path;<br />
perl -MFile::Basename -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext File::Basename;<br />
perl -MFile::Copy -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext File::Copy;<br />
perl -MIO::Handle -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext IO::Handle;<br />
perl -MYAML::XS -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext YAML::XS;<br />
perl -MYAML -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext YAML;<br />
perl -MXML::Simple -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext XML::Simple;<br />
perl -MStorable -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext Storable;<br />
perl -MStatistics::Descriptive -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext Statistics::Descriptive;<br />
perl -MTie::IxHash -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext Tie::IxHash;<br />
perl -MAlgorithm::Combinatorics -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext Algorithm::Combinatorics;<br />
perl -MDevel::Size -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext Devel::Size;<br />
perl -MSort::Key::Radix -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext Sort::Key::Radix;<br />
perl -MSort::Key -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext Sort::Key;<br />
perl -MBit::Vector -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext Bit::Vector;<br />
perl -M"feature 'switch'" -e 1 &gt; /dev/null 2&gt;&amp;1 || cpanm -v --notest -l ext feature;</p></blockquote>
<p>下面是解释为什么这样可以解决问题！！！</p>
<p>&nbsp;</p>
<div>
<p>What follows is a brief explanation of what the commands above do.</p>
<p><code>wget -O- <a href="http://cpanmin.us">http://cpanmin.us</a></code> fetches the latest version of <code>cpanm</code> and prints it to <code>STDOUT</code> which is then piped to <code>perl - -l ~/perl5 App::cpanminus local::lib</code>. The first <code>-</code> tells <code>perl</code> to expect the program to come in on <code>STDIN</code>, this makes <code>perl</code> run the version of <code>cpanm</code> we just downloaded.<code>perl</code> passes the rest of the arguments to <code>cpanm</code>. The <code>-l ~/perl5</code> argument tells <code>cpanm</code> where to install Perl modules, and the other two arguments are two modules to install. <code>[App::cpanmins</code>]<a href="http://search.cpan.org/dist/App-cpanminus/lib/App/cpanminus.pm">1</a> is the package that installs <code>cpanm</code>. <a href="http://search.cpan.org/dist/local-lib/lib/local/lib.pm"><code>local::lib</code></a> is a helper module that manages the environment variables needed to run modules in local directory.</p>
<p>After those modules are installed we run</p>
<pre class=""><code><span class="">eval</span> <span class="">`perl -I ~/perl5/lib/perl5 -Mlocal::lib`</span></code></pre>
<p>to set the environment variables needed to use the local modules and then</p>
<pre class=""><code><span class="">echo </span><span class="">'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`'</span> <span class="">&gt;&gt;</span> <span class="">~/.</span><span class="">profile</span></code></pre>
<p>to ensure we will be able to use them the next time we log in.</p>
<pre class=""><code><span class="">echo </span><span class="">'export MANPATH=$HOME/perl5/man:$MANPATH'</span> <span class="">&gt;&gt;</span> <span class="">~/.</span><span class="">profile</span></code></pre>
<p>will hopefully cause man to find the man pages for your local modules.</p>
</div>
<div>
<p>这种类似的问题被问的特别多！</p>
<p>There's the way documented in <a href="http://faq.perl.org/perlfaq8.html#How_do_I_install_a_m">perlfaq8</a>, which is what <a href="http://search.cpan.org/perldoc/local%3a%3alib#The_bootstrapping_technique">local::lib</a> is doing for you.</p>
<p>It's also a frequently asked StackOverflow question:</p>
<ul>
<li><a href="http://stackoverflow.com/q/1366902/8817">Why does installing certain CPAN modules require root privilege?</a></li>
<li><a href="http://stackoverflow.com/q/102850/8817">How can I install CPAN modules locally without root access (DynaLoader.pm line 229 error)?</a></li>
<li><a href="http://stackoverflow.com/q/786544/8817">How do I tell CPAN.pm to install all modules in a specific directory?</a></li>
<li><a href="http://stackoverflow.com/q/540640/8817">How can I install a CPAN module into a local directory?</a></li>
<li><a href="http://stackoverflow.com/q/251705/8817">How can I use a new Perl module without install permissions?</a></li>
<li><a href="http://stackoverflow.com/q/2980297/8817">How can I use CPAN as a non-root user?</a></li>
<li><a href="http://stackoverflow.com/q/1541638/8817">How can I install local modules with the cpan tool?</a></li>
</ul>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/1474.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
