📄 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>Using the Ports Collection</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Installing Applications: Packages and Ports" href="ports.html" /><link rel="PREVIOUS" title="Using the Packages System" href="packages-using.html" /><link rel="NEXT" title="Post-installation Activities" href="ports-nextsteps.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></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 Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="packages-using.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 4 Installing Applications:Packages and Ports</td><td width="10%" align="right" valign="bottom"><a href="ports-nextsteps.html"accesskey="N">Next</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 Using the PortsCollection</a></h1><p>The following sections provide basic instructions on using the ports collection toinstall or remove programs from your system.</p><div class="SECT2"><h2 class="SECT2"><a id="PORTS-TREE" name="PORTS-TREE">4.5.1 Obtaining the PortsCollection</a></h2><p>Before you can install ports, you must first obtain the ports collection--which isessentially a set of <tt class="FILENAME">Makefiles</tt>, patches, and description filesplaced in <tt class="FILENAME">/usr/ports</tt>.</p><p>When installing your FreeBSD system, <b class="APPLICATION">sysinstall</b> asked ifyou would like to install the ports collection. If you chose no, you can follow theseinstructions to obtain the ports collection:</p><div class="PROCEDURE"><p><b>Sysinstall Method</b></p><p>This method involves using <b class="APPLICATION">sysinstall</b> again to manuallyinstall the ports collection.</p><ol type="1"><li><p>As <tt class="USERNAME">root</tt>, run <tt class="COMMAND">/stand/sysinstall</tt> asshown below:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">/stand/sysinstall</kbd></pre></li><li><p>Scroll down and select <span class="GUIMENUITEM">Configure</span>, press <bclass="KEYCAP">Enter</b>.</p></li><li><p>Scroll down and select <span class="GUIMENUITEM">Distributions</span>, press <bclass="KEYCAP">Enter</b>.</p></li><li><p>Scroll down to <span class="GUIMENUITEM">ports</span>, press <bclass="KEYCAP">Space</b>.</p></li><li><p>Scroll up to <span class="GUIMENUITEM">Exit</span>, press <bclass="KEYCAP">Enter</b>.</p></li><li><p>Select your desired installation media, such as CDROM, FTP, and so on.</p></li><li><p>Scroll up to <span class="GUIMENUITEM">Exit</span> and press <bclass="KEYCAP">Enter</b>.</p></li><li><p>Press <b class="KEYCAP">X</b> to exit <b class="APPLICATION">sysinstall</b>.</p></li></ol></div><p>The alternative method to obtain and keep your ports collection up to date is by using<b class="APPLICATION">CVSup</b>. Look at the ports <b class="APPLICATION">CVSup</b>file, <tt class="FILENAME">/usr/share/examples/cvsup/ports-supfile</tt>. See <ahref="cvsup.html">Using CVSup</a> (<a href="cvsup.html">Section A.5</a>) for moreinformation on using <b class="APPLICATION">CVSup</b> and this file.</p><div class="PROCEDURE"><p><b>CVSup Method</b></p><p>This is a quick method for getting the ports collection using <bclass="APPLICATION">CVSup</b>. If you want to keep your ports tree up to date, or learnmore about <b class="APPLICATION">CVSup</b>, read the previously mentioned sections.</p><ol type="1"><li><p>Install the <a href="http://www.FreeBSD.org/cgi/url.cgi?ports/net/cvsup/pkg-descr"><ttclass="FILENAME">net/cvsup</tt></a> port. See <a href="cvsup.html#CVSUP-INSTALL">CVSupInstallation</a> (<a href="cvsup.html#CVSUP-INSTALL">Section A.5.2</a>) for moredetails.</p></li><li><p>As <tt class="USERNAME">root</tt>, copy <ttclass="FILENAME">/usr/share/examples/cvsup/ports-supfile</tt> to a new location, such as<tt class="FILENAME">/root</tt> or your home directory.</p></li><li><p>Edit <tt class="FILENAME">ports-supfile</tt>.</p></li><li><p>Change <var class="REPLACEABLE">CHANGE_THIS.FreeBSD.org</var> to a <bclass="APPLICATION">CVSup</b> server near you. See <ahref="cvsup.html#CVSUP-MIRRORS">CVSup Mirrors</a> (<ahref="cvsup.html#CVSUP-MIRRORS">Section A.5.7</a>) for a complete listing of mirrorsites.</p></li><li><p>Run <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>Running this command later will download and apply all the recent changes to yourports collection, except actually rebuilding the ports for your own system.</p></li></ol></div></div><div class="SECT2"><h2 class="SECT2"><a id="PORTS-SKELETON" name="PORTS-SKELETON">4.5.2 InstallingPorts</a></h2><p>The first thing that should be explained when it comes to the ports collection is whatis actually meant by a ``skeleton''. In a nutshell, a port skeleton is a minimal set offiles that tell your FreeBSD system how to cleanly compile and install a program. Eachport skeleton includes:</p><ul><li><p>A <tt class="FILENAME">Makefile</tt>. The <tt class="FILENAME">Makefile</tt> containsvarious statements that specify how the application should be compiled and where itshould be installed on your system.</p></li><li><p>A <tt class="FILENAME">distinfo</tt> file. This file contains information about thefiles that must be downloaded to build the port and their checksums, to verify that fileshave not been corrupted during the download using <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=md5&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">md5</span>(1)</span></a>.</p></li><li><p>A <tt class="FILENAME">files</tt> directory. This directory contains patches to makethe program compile and install on your FreeBSD system. Patches are basically small filesthat specify changes to particular files. They are in plain text format, and basicallysay ``Remove line 10'' or ``Change line 26 to this ...''. Patches are also known as``diffs'' because they are generated by the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=diff&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">diff</span>(1)</span></a> program.</p><p>This directory may also contain other files used to build the port.</p></li><li><p>A <tt class="FILENAME">pkg-descr</tt> file. This is a more detailed, oftenmultiple-line, description of the program.</p></li><li><p>A <tt class="FILENAME">pkg-plist</tt> file. This is a list of all the files that willbe installed by the port. It also tells the ports system what files to remove upondeinstallation.</p></li></ul><p>Some ports have other files, such as <tt class="FILENAME">pkg-message</tt>. The portssystem uses these files to handle special situations. If you want more details on thesefiles, and on ports in general, check out the <ahref="../../../../doc/en_US.ISO8859-1/books/porters-handbook/index.html"target="_top">FreeBSD Porter's Handbook</a>.</p><p>The port includes instructions on how to build source code, but does not include theactual source code. You can get the source code from a CD-ROM or from the Internet.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>Note:</b> You must be logged in as <tt class="USERNAME">root</tt> to installports.</p></blockquote></div><div class="WARNING"><blockquote class="WARNING"><p><b>Warning:</b> Before installing any port, you should be sure to have an up-to-dateports collection and you should check <a href="http://vuxml.freebsd.org/"target="_top">http://vuxml.freebsd.org/</a> for security issues related to your port.</p><p>A security vulnerabilities check can be automatically done by <bclass="APPLICATION">portaudit</b> before any new application installation. This tool canbe found in the ports collection (<ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/security/portaudit/pkg-descr"><ttclass="FILENAME">security/portaudit</tt></a>). Consider running <ttclass="COMMAND">portaudit -F</tt> before installing a new port, to fetch the currentvulnerabilities database. A security audit and an update of the database will beperformed during the daily security system check. For more informations read the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=portaudit&sektion=1&manpath=FreeBSD+Ports"><span class="CITEREFENTRY"><span class="REFENTRYTITLE">portaudit</span>(1)</span></a> and<a href="http://www.FreeBSD.org/cgi/man.cgi?query=periodic&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">periodic</span>(8)</span></a> manualpages.</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>Note:</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">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -