How to install an updated version of PEAR / PHPUnit on Ubuntu?

42

38

Most tutorials online show how to install PEAR by doing this:

sudo apt-get install php-pear

This installs version 1.6.1. It works great because it's super easy! My problem is that I want to install PHPUnit and it requires PEAR version 1.8.1 so my install of PHPUnit failed. So how do I install a newer version of PEAR on Ubuntu?

Andrew

Posted 2009-10-14T00:22:35.477

Reputation: 11 982

Answers

78

First, install PEAR.

sudo apt-get install php-pear

Next, tell PEAR to update its own channel.

sudo pear channel-update pear.php.net

Then, tell PEAR to upgrade itself to the newest version.

sudo pear upgrade-all

You should now have the newest version of PEAR installed.

To install PHPUnit, let PEAR know where to find PHPUnit.

sudo pear channel-discover pear.phpunit.de

Then install PHPUnit. (the -a makes sure all dependency packages are also installed)

sudo pear install -a phpunit/PHPUnit

Update:

According to the latest PHPUnit installation documentation, you can install PHPUnit with the following commands (make sure you have updated PEAR first):

sudo pear config-set auto_discover 1
sudo pear install pear.phpunit.de/PHPUnit

Andrew

Posted 2009-10-14T00:22:35.477

Reputation: 11 982

Incidentally it might be good to add apt-get install curl and sudo pecl install xdebug for code coverage – David – 2011-04-18T04:08:59.390

3actually, I just discovered that apt-get install php5-xdebug is the easiest. =] – Andrew – 2011-10-04T20:31:08.303

2I've been burned a few times in the version difference between what is in the public repo and what's on pear, last time was earlier this year ( 2011 ) where there was a regression in the Ubuntu repo. – David – 2011-10-04T21:18:14.823

9

Last versions of PhpUnit require ez/zeta components & symfony's YAML lib

sudo apt-get install php-pear
sudo pear channel-update pear.php.net
sudo pear upgrade-all
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony-project.com
sudo pear install -a phpunit/PHPUnit

See the last updated installation tutorial here

Ronan

Posted 2009-10-14T00:22:35.477

Reputation: 209

3

If installation using above command failed, You might need to install Net_URL2-0.3.1 and then HTTP_Request2-2.0.0RC1 before installation of PHPUnit on Ubuntu. Find the latest version of the above packages and install them.

Example:

sudo apt-get install curl

sudo pear install pear/Net_URL2-0.3.1

sudo pear install pear/HTTP_Request2-2.0.0RC1

sudo pear install -a phpunit/PHPUnit

Pi3cH

Posted 2009-10-14T00:22:35.477

Reputation: 51