📄 ports-using.html
字号:
directories listed in the <tt class="ENVAR">PATH</tt> environment variable, to speed uplookup operations for the executable file of these commands. If you are using one ofthese shells, you might have to use the <tt class="COMMAND">rehash</tt> command afterinstalling a port, before the newly installed commands can be used. This is true for bothshells that are part of the base-system (such as <tt class="COMMAND">tcsh</tt>) andshells that are available as ports (for instance, <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/shells/zsh/pkg-descr"><ttclass="FILENAME">shells/zsh</tt></a>).</p></blockquote></div><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> Please be aware that the licenses of a few ports do not allow for inclusionon the CD-ROM. This could be because a registration form needs to be filled out beforedownloading or redistribution is not allowed, or for another reason. If you wish toinstall a port not included on the CD-ROM, you will need to be online in order to do so(see the <a href="ports-using.html#PORTS-INET">next section</a>).</p></blockquote></div></div><div class="SECT3"><h3 class="SECT3"><a id="PORTS-INET" name="PORTS-INET">4.5.2.2. Installing Ports from theInternet</a></h3><p>As with the last section, this section makes an assumption that you have a workingInternet connection. If you do not, you will need to perform the <ahref="ports-using.html#PORTS-CD">CD-ROM installation</a>, or put a copy of the distfileinto <tt class="FILENAME">/usr/ports/distfiles</tt> manually.</p><p>Installing a port from the Internet is done exactly the same way as it would be if youwere installing from a CD-ROM. The only difference between the two is that the distfileis downloaded from the Internet instead of read from the CD-ROM.</p><p>The steps involved are identical:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make install</kbd>>> lsof_4.57D.freebsd.tar.gz doesn't seem to exist in /usr/ports/distfiles/.>> Attempting to fetch from ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/.Receiving lsof_4.57D.freebsd.tar.gz (439860 bytes): 100%439860 bytes transferred in 18.0 seconds (23.90 kBps)===> 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]...===> 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>As you can see, the only difference is the line that tells you where the system isfetching the port distfile from.</p><p>The ports system uses <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">fetch</span>(1)</span> to download the files, which honors variousenvironment variables, including <tt class="ENVAR">FTP_PASSIVE_MODE</tt>, <ttclass="ENVAR">FTP_PROXY</tt>, and <tt class="ENVAR">FTP_PASSWORD</tt>. You may need toset one or more of these if you are behind a firewall, or need to use an FTP/HTTP proxy.See <span class="CITEREFENTRY"><span class="REFENTRYTITLE">fetch</span>(3)</span> for thecomplete list.</p><p>For users which cannot be connected all the time, the <tt class="COMMAND">make <ttclass="MAKETARGET">fetch</tt></tt> option is provided. Just run this command at the toplevel directory (<tt class="FILENAME">/usr/ports</tt>) and the required files will bedownloaded for you. This command will also work in the lower level categories, forexample: <tt class="FILENAME">/usr/ports/net</tt>. Note that if a port depends onlibraries or other ports this will <span class="emphasis"><iclass="EMPHASIS">not</i></span> fetch the distfiles of those ports too. Replace <ttclass="MAKETARGET">fetch</tt> with <tt class="MAKETARGET">fetch-recursive</tt> if youwant to fetch all the dependencies of a port too.</p><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> You can build all the ports in a category or as a whole by running <ttclass="COMMAND">make</tt> in the top level directory, just like the aforementioned <ttclass="COMMAND">make <tt class="MAKEVAR">fetch</tt></tt> method. This is dangerous,however, as some ports cannot co-exist. In other cases, some ports can install twodifferent files with the same filename.</p></blockquote></div><p>In some rare cases, users may need to acquire the tarballs from a site other than the<tt class="MAKEVAR">MASTER_SITES</tt> (the location where files are downloaded from). Youcan override the <tt class="MAKEVAR">MASTER_SITES</tt> option with the followingcommand:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">cd /usr/ports/<varclass="REPLACEABLE">directory</var></kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make MASTER_SITE_OVERRIDE= \ftp://ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/ fetch</kbd></pre><p>In this example we change the <tt class="MAKEVAR">MASTER_SITES</tt> option to <ttclass="HOSTID">ftp.FreeBSD.org/pub/FreeBSD/ports/distfiles/</tt>.</p><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> Some ports allow (or even require) you to provide build options which canenable/disable parts of the application which are unneeded, certain security options, andother customizations. A few which come to mind are <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/www/mozilla/pkg-descr"><ttclass="FILENAME">www/mozilla</tt></a>, <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/security/gpgme/pkg-descr"><ttclass="FILENAME">security/gpgme</tt></a>, and <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/mail/sylpheed-claws/pkg-descr"><ttclass="FILENAME">mail/sylpheed-claws</tt></a>. A message will be displayed when optionssuch as these are available.</p></blockquote></div></div><div class="SECT3"><h3 class="SECT3"><a id="AEN5792" name="AEN5792">4.5.2.3. Overriding the Default PortsDirectories</a></h3><p>Sometimes it is useful (or mandatory) to use a different distfiles and portsdirectory. The <tt class="MAKEVAR">PORTSDIR</tt> and <tt class="MAKEVAR">PREFIX</tt>variables can override the default directories. For example:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">make PORTSDIR=/usr/home/example/ports install</kbd></pre><p>will compile the port in <tt class="FILENAME">/usr/home/example/ports</tt> and installeverything under <tt class="FILENAME">/usr/local</tt>.</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">make PREFIX=/usr/home/example/local install</kbd></pre><p>will compile it in <tt class="FILENAME">/usr/ports</tt> and install it in <ttclass="FILENAME">/usr/home/example/local</tt>.</p><p>And of course,</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">make PORTSDIR=../ports PREFIX=../local install</kbd></pre><p>will combine the two (it is too long to completely write on this page, but it shouldgive you the general idea).</p><p>Alternatively, these variables can also be set as part of your environment. Read themanual page for your shell for instructions on doing so.</p></div><div class="SECT3"><h3 class="SECT3"><a id="AEN5815" name="AEN5815">4.5.2.4. Dealing with <ttclass="COMMAND">imake</tt></a></h3><p>Some ports that use <tt class="COMMAND">imake</tt> (a part of the X Window System) donot work well with <tt class="MAKEVAR">PREFIX</tt>, and will insist on installing under<tt class="FILENAME">/usr/X11R6</tt>. Similarly, some Perl ports ignore <ttclass="MAKEVAR">PREFIX</tt> and install in the Perl tree. Making these ports respect <ttclass="MAKEVAR">PREFIX</tt> is a difficult or impossible job.</p></div></div><div class="SECT2"><h2 class="SECT2"><a id="PORTS-REMOVING" name="PORTS-REMOVING">4.5.3. Removing InstalledPorts</a></h2><p>Now that you know how to install ports, you are probably wondering how to remove them,just in case you install one and later on decide that you installed the wrong port. Wewill remove our previous example (which was <tt class="COMMAND">lsof</tt> for those ofyou not paying attention). As with installing ports, the first thing you must do ischange to the port directory, <tt class="FILENAME">/usr/ports/sysutils/lsof</tt>. Afteryou change directories, you are ready to uninstall <tt class="COMMAND">lsof</tt>. This isdone with the <tt class="COMMAND">make deinstall</tt> command:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">cd /usr/ports/sysutils/lsof</kbd><samp class="PROMPT">#</samp> <kbd class="USERINPUT">make deinstall</kbd>===> Deinstalling for lsof-4.57</pre><p>That was easy enough. You have removed <tt class="COMMAND">lsof</tt> from your system.If you would like to reinstall it, you can do so by running <tt class="COMMAND">makereinstall</tt> from the <tt class="FILENAME">/usr/ports/sysutils/lsof</tt> directory.</p><p>The <tt class="COMMAND">make deinstall</tt> and <tt class="COMMAND">makereinstall</tt> sequence does not work once you have run <tt class="COMMAND">makeclean</tt>. If you want to deinstall a port after cleaning, use <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">pkg_delete</span>(1)</span> as discussedin the <a href="packages-using.html">Packages section of the Handbook</a>.</p></div><div class="SECT2"><h2 class="SECT2"><a id="PORTS-DISK-SPACE" name="PORTS-DISK-SPACE">4.5.4. Ports and DiskSpace</a></h2><p>Using the ports collection can defiantly eat up your disk space. For this reason youshould always remember to clean up the work directories using the <ttclass="COMMAND">make <tt class="MAKEVAR">clean</tt></tt> option. This will remove the <ttclass="FILENAME">work</tt> directory after a port has been built, and installed. You canalso remove the tar files from the <tt class="FILENAME">distfiles</tt> directory, andremove the installed ports when their use has delimited.</p><p>Some users choose to limit the port categories by placing an entry in the <ttclass="FILENAME">refuse</tt> file. This way when they run the <bclass="APPLICATION">CVSup</b> application, it will not download the files in thatcategory.</p></div><div class="SECT2"><h2 class="SECT2"><a id="PORTS-UPGRADING" name="PORTS-UPGRADING">4.5.5. UpgradingPorts</a></h2><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> Once you updated your ports collection, before attempting a port upgrade,you should check the <tt class="FILENAME">/usr/ports/UPDATING</tt> file. This filedescribes various issues and additional steps users may encounter and need to performwhen updating a port.</p></blockquote></div><p>Keeping your ports up to date can be a tedious job. For instance, to upgrade a portyou would go to the ports directory, build the port, deinstall the old port, install thenew port, and then clean up after the build. Imagine doing that for five ports, tediousright? This was a large problem for system administrators to deal with, and now we haveutilities which do this for us. For instance the <ahref="http://www.FreeBSD.org/cgi/url.cgi?ports/sysutils/portupgrade/pkg-descr"><ttclass="FILENAME">sysutils/portupgrade</tt></a> utility will do everything for you! Justinstall it like you would any other port, using the <tt class="COMMAND">make <ttclass="MAKEVAR">install clean</tt></tt> command.</p><p>Now create a database with the <tt class="COMMAND">pkgdb -F</tt> command. This willread the list of installed ports and create a database file in the <ttclass="FILENAME">/var/db/pkg</tt> directory. Now when you run <ttclass="COMMAND">portupgrade -a</tt>, it will read this and the ports <ttclass="FILENAME">INDEX</tt> file. Finally, <b class="APPLICATION">portupgrade</b> willbegin to download, build, backup, install, and clean the ports which have been updated.<b class="APPLICATION">portupgrade</b> comes with a lot of options for different usecases, the most important ones will be presented below.</p><p>If you want to upgrade only a certain application, not the complete database, use <ttclass="COMMAND">portupgrade <var class="REPLACEABLE">pkgname</var></tt>, include theflags <var class="OPTION">-r</var> if <b class="APPLICATION">portupgrade</b> should acton all those packages depending on the given package as well, and <varclass="OPTION">-R</var> to act on all packages required by the given packages. To usepackages instead of ports for installation, provide <var class="OPTION">-P</var> and tojust fetch distfiles without building or installing anything, use <varclass="OPTION">-F</var>. For further information see <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">portupgrade</span>(1)</span>.</p><div class="NOTE"><blockquote class="NOTE"><p><b>注:</b> It is important to regularly update the package database using <ttclass="COMMAND">pkgdb -F</tt> to fix inconsistencies, especially when <bclass="APPLICATION">portupgrade</b> asks you to. Do not abort <bclass="APPLICATION">portupgrade</b> while it is updating the package database, this willleave you an inconsistent database.</p></blockquote></div><p>Other utilities exist which will do this, check out the <ttclass="FILENAME">ports/sysutils</tt> directory and see what you come up with.</p></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="packages-using.html"accesskey="P">后退</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">起点</a></td><td width="33%" align="right" valign="top"><a href="ports-nextsteps.html"accesskey="N">前进</a></td></tr><tr><td width="33%" align="left" valign="top">使用Packages系统</td><td width="34%" align="center" valign="top"><a href="ports.html"accesskey="U">上一级</a></td><td width="33%" align="right" valign="top">Post-installation Activities</td></tr></table></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -