📄 ports-using.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>使用Ports Collection</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD 使用手册" href="index.html" /><link rel="UP" title="安装应用程序: Packages 和 Ports" href="ports.html" /><link rel="PREVIOUS" title="使用Packages系统" href="packages-using.html" /><link rel="NEXT" title="Post-installation Activities" href="ports-nextsteps.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD 使用手册</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="packages-using.html"accesskey="P">后退</a></td><td width="80%" align="center" valign="bottom">章 4. 安装应用程序: Packages 和 Ports</td><td width="10%" align="right" valign="bottom"><a href="ports-nextsteps.html"accesskey="N">前进</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="PORTS-USING" name="PORTS-USING">4.5. 使用PortsCollection</a></h1><p>下面的章节提供了使用ports collection来安装或卸载程序的基本用法。</p><div class="SECT2"><h2 class="SECT2"><a id="PORTS-TREE" name="PORTS-TREE">4.5.1. 获得PortsCollection</a></h2><p>在您能使用ports之前, 您必须先获得ports collection--本质上是<ttclass="FILENAME">/usr/ports</tt>目录下的一堆 <tt class="FILENAME">Makefiles</tt>,补丁,和描述文件。</p><p>在您安装FreeBSD系统的时候,<bclass="APPLICATION">sysinstall</b>会询问您是否需要安装ports collection.如果您选择no,那您可以根据下面的指令来安装ports collection:</p><div class="PROCEDURE"><p><b>Sysinstall 方式</b></p><p>这种方式使用<b class="APPLICATION">sysinstall</b>再次手动安装ports collection。</p><ol type="1"><li><p>用<tt class="USERNAME">root</tt>用户, 运行 <ttclass="COMMAND">/stand/sysinstall</tt>命令,像下面显示的:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">/stand/sysinstall</kbd></pre></li><li><p>选择<span class="GUIMENUITEM">Configure</span>, 按<b class="KEYCAP">Enter</b>。</p></li><li><p>选择<span class="GUIMENUITEM">Distributions</span>, 按 <bclass="KEYCAP">Enter</b>。</p></li><li><p>选择<span class="GUIMENUITEM">ports</span>, 按<b class="KEYCAP">Space</b>。</p></li><li><p>选择<span class="GUIMENUITEM">Exit</span>, 按<b class="KEYCAP">Enter</b>。</p></li><li><p>选择您的安装介质,就像CDROM,FTP,等等</p></li><li><p>选择<span class="GUIMENUITEM">Exit</span>并按<b class="KEYCAP">Enter</b>。</p></li><li><p>按<b class="KEYCAP">X</b>键退出<b class="APPLICATION">sysinstall</b>。</p></li></ol></div><p>您可以使用<b class="APPLICATION">CVSup</b>,这个程序让您获得和更新 ports collection。<b class="APPLICATION">CVSup</b>需要使用 <ttclass="FILENAME">/usr/share/examples/cvsup/ports-supfile</tt>这个配置文件。如果您想获得关于<b class="APPLICATION">CVSup</b>这个应用程序的更多信息,请看<ahref="cvsup.html">使用 CVSup</a> (<a href="cvsup.html">µÚ A.5节</a>)和本文件。</p><div class="PROCEDURE"><p><b>CVSup 方法</b></p><p>使用<b class="APPLICATION">CVSup</b>获得 ports collection ,是一个非常快捷的方法。如果您想保持您的 ports 树的最新状态,或学习更多关于<bclass="APPLICATION">CVSup</b>的内容您可以阅读刚才提及的内容。</p><ol type="1"><li><p>安装<a href="http://www.FreeBSD.org/cgi/url.cgi?ports/net/cvsup/pkg-descr"><ttclass="FILENAME">net/cvsup</tt></a> port。详情请参阅<ahref="cvsup.html#CVSUP-INSTALL">CVSup 安装</a> (<ahref="cvsup.html#CVSUP-INSTALL">µÚ A.5.2 节</a>)。</p></li><li><p>用<tt class="USERNAME">root</tt> 用户,复制 <ttclass="FILENAME">/usr/share/examples/cvsup/ports-supfile</tt> 到一个新的地方,比如 <ttclass="FILENAME">/root</tt> 和您的家目录。</p></li><li><p>编辑 <tt class="FILENAME">ports-supfile</tt>。</p></li><li><p>修改 <var class="REPLACEABLE">CHANGE_THIS.FreeBSD.org</var> 到离您比较近的<bclass="APPLICATION">CVSup</b> 服务器。请看 <a href="cvsup.html#CVSUP-MIRRORS">CVSup镜像</a> (<a href="cvsup.html#CVSUP-MIRRORS">µÚ A.5.7 节</a>)服务器的完整列表。</p></li><li><p>运行 <tt class="COMMAND">cvsup</tt>:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">cvsup -g -L 2 <varclass="REPLACEABLE">/root/ports-supfile</var></kbd></pre></li><li><p>运行这个命令之后将下载和应用所有变化的ports系统,除了在您的系统中重建ports系统。</p></li></ol></div></div><div class="SECT2"><h2 class="SECT2"><a id="PORTS-SKELETON" name="PORTS-SKELETON">4.5.2. 安装 Ports</a></h2><p>当提到Ports collection时,第一个要说明的就是何谓“``skeleton''”。简单地说,一个portskeleton让一个程序在FreeBSD上简洁地编译并安装的所需文件的最小组合。每个portskeleton包含:</p><ul><li><p>一个 <tt class="FILENAME">Makefile</tt>。<ttclass="FILENAME">Makefile</tt>包括好几个部分,指出应用程序是如何编译和它将被安装在系统的哪个地方。</p></li><li><p>一个 <tt class="FILENAME">distinfo</tt>文件。这个文件包括这些信息:这些文件用来对下载后的文件checksums,使用 <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">md5</span>(1)</span>来确保在下载过程中文件不会被破坏。</p></li><li><p>一个<ttclass="FILENAME">files</tt>目录。这个目录包括在您的FreeBSD系统上编译和安装程序需要用到的补丁。这些补丁基本上都是些小文件,指出特定文件作了哪些修正。他们都是纯文本的的格式,基本上是这样的``Removeline 10'' 或``Change line 26 to this ...'',补丁文件使用了``diffs'',他们由 <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">diff</span>(1)</span> 程序产生。</p><p>这个目录也包含了在建立port时要用到的其它文件T。</p></li><li><p>一个<ttclass="FILENAME">pkg-descr</tt>文件。这是一个提供更多细节,有软件的多行描述。</p></li><li><p>一个 <tt class="FILENAME">pkg-plist</tt>文件。这是即将被安装的所有文件的列表。它告诉ports系统在重新安装时什么文件需要被删除。</p></li></ul><p>一些ports还有些其它的文件,就像 <ttclass="FILENAME">pkg-message</tt>。ports系统会在特殊的情况下使用这些文件。如果您想知道这些文件更多的细节以及ports的概要,请参阅<a href="../../../../doc/en_US.ISO8859-1/books/porters-handbook/index.html"target="_top">FreeBSD Porter's Handbook</a>.</p><p>port里面包含着如何编译源代码的指令,但不包含真实的源代码。您可以在网上或CD-ROM上获得源代码。Source code is distributed in whatever manner the software author desires. Frequentlythis is a tarred and gzipped file, but it might be compressed with some other tool oreven uncompressed. The program source code, whatever form it comes in, is called a``distfile''. The two methods for installing a FreeBSD port are described below.</p><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> 您必须使用 <tt class="USERNAME">root</tt> 用户登录后安装ports.</p></blockquote></div><div class="WARNING"><blockquote class="WARNING"><p><b>警告</b>在安装任何 port 之前, 应该首先确保已经更新到了最新的 ports collection,并检查 <a href="http://vuxml.freebsd.org/" target="_top">http://vuxml.freebsd.org/</a>中是否有与那个 port 有关的安全问题。</p><p>在安装应用程序之前, 可以使用 <b class="APPLICATION">portaudit</b>来自动地检查是否存在已知的安全问题。 这个工具同样可以在 ports collection (<ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/security/portaudit/pkg-descr"><ttclass="FILENAME">security/portaudit</tt></a>) 中找到。 在安装新的 port 之前,可以考虑先运行一下 <tt class="COMMAND">portaudit -F</tt> 来抓取最新的漏洞数据库。在每天的周期性系统安全检察时, 数据库会被自动更新, 并且会在这之后实施安全审计。欲了解进一步的情况,请参阅 <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">portaudit</span>(1)</span> 和 <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">periodic</span>(8)</span>。</p></blockquote></div><div class="SECT3"><h3 class="SECT3"><a id="PORTS-CD" name="PORTS-CD">4.5.2.1. Installing Ports from aCD-ROM</a></h3><p>The FreeBSD Project's official CD-ROM images no longer include distfiles. They take upa lot of room that is better used for precompiled packages. CD-ROM products such as theFreeBSD PowerPak do include distfiles, and you can order these sets from a vendor such asthe <a href="http://www.freebsdmall.com/" target="_top">FreeBSD Mall</a>. This sectionassumes you have such a FreeBSD CD-ROM set.</p><p>Place your FreeBSD CD-ROM in the drive. Mount it on <tt class="FILENAME">/cdrom</tt>.(If you use a different mount point, the install will not work.) To begin, change to thedirectory for the port you want to install:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">cd /usr/ports/sysutils/lsof</kbd></pre><p>Once inside the <tt class="FILENAME">lsof</tt> directory, you will see the portskeleton. The next step is to compile, or ``build'', the port. This is done by simplytyping <tt class="COMMAND">make</tt> at the prompt. Once you have done so, you should seesomething like this:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make</kbd>>> lsof_4.57D.freebsd.tar.gz doesn't seem to exist in /usr/ports/distfiles/.>> Attempting to fetch from file:/cdrom/ports/distfiles/.===> Extracting for lsof-4.57...[extraction output snipped]...>> Checksum OK for lsof_4.57D.freebsd.tar.gz.===> Patching for lsof-4.57===> Applying FreeBSD patches for lsof-4.57===> Configuring for lsof-4.57...[configure output snipped]...===> Building for lsof-4.57...[compilation output snipped]...<samp class="PROMPT">#</samp></pre><p>Notice that once the compile is complete you are returned to your prompt. The nextstep is to install the port. In order to install it, you simply need to tack one wordonto the <tt class="COMMAND">make</tt> command, and that word is <ttclass="COMMAND">install</tt>:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make install</kbd>===> Installing for lsof-4.57...[installation output snipped]...===> Generating temporary packing list===> Compressing manual pages for lsof-4.57===> Registering installation for lsof-4.57===> SECURITY NOTE: This port has installed the following binaries which execute with increased privileges.<samp class="PROMPT">#</samp></pre><p>Once you are returned to your prompt, you should be able to run the application youjust installed. Since <tt class="COMMAND">lsof</tt> is a program that runs with increasedprivileges, a security warning is shown. During the building and installation of ports,you should take heed of any other warnings that may appear.</p><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> You can save an extra step by just running <tt class="COMMAND">makeinstall</tt> instead of <tt class="COMMAND">make</tt> and <tt class="COMMAND">makeinstall</tt> as two separate steps.</p></blockquote></div><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> Some shells keep a cache of the commands that are available in the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -