The PEAR Package Tour: PEAR Basics - Installing Packages
(Page 3 of 5 )
Now that you have a working PEAR installation, you’ll want to install some packages, as that’s the whole point. Installation is done through the “pear” installer command that you should have set up in the previous section of this article.
The installer includes a great help system, which can be accessed from the command line. For example, you can find a list of commands by simply executing “pear.” Or use the help function on individual commands for more details:
> pear help install
pear install [options] [channel/]<package> ...
Installs one or more PEAR packages. You can specify a package to
install in four ways:
"Package-1.0.tgz" : installs from a local file
"http://example.com/Package-1.0.tgz" : installs from
anywhere on the net.
"package.xml" : installs the package described in
package.xml. Useful for testing, or for wrapping a PEAR package in
another package manager such as RPM.
"Package[-version/state][.tar]" : queries your default channel's server
(pear.php.net) and downloads the newest package with
the preferred quality/state (stable).
…
The output goes on for many more pages, describing all the options for the install command. As you can see, we can install packages in a couple ways. The easiest is the last option presented, installing from your default channel by package name. By default your install channel will be pear.php.net, and is simply a server where the installer will look for packages and updates.
File is the file handling abstraction layer from PEAR, and we’ll install that as an example:
> sudo pear install File
downloading File-1.3.0.tgz ...
Starting to download File-1.3.0.tgz (25,727 bytes)
.........done: 25,727 bytes
install ok: channel://pear.php.net/File-1.3.0
That’s all there is to it. You can see here that I needed to run the command as root (via sudo) to install it globally. With shared hosting, you will run it as yourself. You can easily verify that a package is installed by running the install command again.
> sudo pear install File
Ignoring installed package pear/File
Nothing to install
You can upgrade an existing package with the upgrade command:
> sudo pear upgrade File
upgrade ok: channel://pear.php.net/File-1.3.0
If the package is up to date, PEAR will simply tell you that there is nothing to upgrade.
Some packages within the PEAR repository are still considered alpha or beta, because they are incomplete, poorly documented or not fully tested… but these packages are often quite useful. When you try to install these, PEAR will by default tell you that the package isn’t available because it is not available in a “stable” state. You can override this behavior with the preferred_state option.
> sudo pear -d preferred_state=alpha install Services_Yahoo
downloading Services_Yahoo-0.2.0.tgz ...
Starting to download Services_Yahoo-0.2.0.tgz (13,381 bytes)
.....done: 13,381 bytes
install ok: channel://pear.php.net/Services_Yahoo-0.2.0
Finally, PEAR makes the management of dependencies between packages very easy. You simply pass the –alldeps or –onlyreqdeps flags when installing. The –alldeps flag will ensure that all capabilities of the package are enabled, whereas –onlyreqdeps will install the bare minimum requirements for the package to run. As shown in this example, PEAR will grab the package, determine any dependencies and then repeat the process with those dependencies, all from one command.
$ pear install --onlyreqdeps html_page2
WARNING: "pear/HTML_Common" is deprecated in favor of "pear/HTML_Common2"
downloading HTML_Page2-0.5.0beta.tgz ...
Starting to download HTML_Page2-0.5.0beta.tgz (15,467 bytes)
......done: 15,467 bytes
downloading HTML_Common-1.2.4.tgz ...
Starting to download HTML_Common-1.2.4.tgz (4,519 bytes)
...done: 4,519 bytes
install ok: channel://pear.php.net/HTML_Common-1.2.4
install ok: channel://pear.php.net/HTML_Page2-0.5.0beta
Next: Core PEAR Classes >>
More PEAR Articles Articles
More By Chris Moyer