4.2 安裝軟體的各種方式介紹

通常要在 UNIX® 系統上安裝軟體時,有幾個步驟要作:

  1. 先下載該軟體壓縮檔(tarball),有可能是原始碼或是 binary 執行檔。

  2. 解開該壓縮檔。(通常是以 compress(1) , gzip(1)bzip2(1) 壓縮的)

  3. 閱讀相關文件檔,以了解如何安裝。(通常檔名是 INSTALLREADME, 或在 doc/ 目錄下的一些文件)

  4. 如果所下載的是原始碼,可能要先修改 Makefile 或是執行 ./configure 之類的 script ,接著再編譯該軟體。

  5. 最後測試再測試與安裝。

如果一切順利的話,就這麼簡單。如果在安裝非專門設計(移植)給 FreeBSD 的軟體時出問題, 那可能需要修改一下它的程式碼,才能正常使用。

當然,我們可以在 FreeBSD 上使用上述的傳統方式來安裝軟體,但是,我們還有更簡單的選擇。 FreeBSD 提供了兩種省事的軟體管理機制: packages 和 ports。就在寫這篇文章的時候, 已經有超過 13,300 個 port 軟體可以使用。

For any given application, the FreeBSD package for that application is a single file which you must download. The package contains pre-compiled copies of all the commands for the application, as well as any configuration files or documentation. A downloaded package file can be manipulated with FreeBSD package management commands, such as pkg_add(1), pkg_delete(1), pkg_info(1), and so on. Installing a new application can be carried out with a single command.

A FreeBSD port for an application is a collection of files designed to automate the process of compiling an application from source code.

Remember that there are a number of steps you would normally carry out if you compiled a program yourself (downloading, unpacking, patching, compiling, installing). The files that make up a port contain all the necessary information to allow the system to do this for you. You run a handful of simple commands and the source code for the application is automatically downloaded, extracted, patched, compiled, and installed for you.

In fact, the ports system can also be used to generate packages which can later be manipulated with pkg_add and the other package management commands that will be introduced shortly.

Both packages and ports understand dependencies. Suppose you want to install an application that depends on a specific library being installed. Both the application and the library have been made available as FreeBSD ports and packages. If you use the pkg_add command or the ports system to add the application, both will notice that the library has not been installed, and automatically install the library first.

Given that the two technologies are quite similar, you might be wondering why FreeBSD bothers with both. Packages and ports both have their own strengths, and which one you use will depend on your own preference.

Package 好處在於:

Ports 好處在於:

To keep track of updated ports, subscribe to the FreeBSD ports mailing list and the FreeBSD ports bugs mailing list.

Warning: Before installing any application, you should check http://vuxml.freebsd.org/ for security issues related to your application.

You can also install security/portaudit which will automatically check all installed applications for known vulnerabilities; a check will be also performed before any port build. Meanwhile, you can use the command portaudit -F -a after you have installed some packages.

The remainder of this chapter will explain how to use packages and ports to install and manage third party software on FreeBSD.

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.