phpunit command not found

In this troubleshooting guide we learn how to fix phpunit command not found error message

Introduction

When you run more command in linux terminal / console, you get the following error message

phpunit: command not found

or when using sudo you get the following error message

sudo: phpunit: command not found

Solutions to phpunit: command not found

How To Fix phpunit: command not found in Ubuntu / Debian / Kali Linux / Raspbian

In Ubuntu phpunit is provided by phpunit package.

phpunit is:

Unit testing allows you to write small test methods which verify units of functionality in your program. It is a powerful technique for improving the quality of your software, preventing regressions, and allowing confident refactoring of your code.

PHPUnit is a unit testing suite for the PHP language, modelled on the xUnit testing framework, designed by Kent Beck and Erich Gamma. If you’ve used JUnit (for Java), PyUnit (for Python), CxxUnit (for C++), or any of the other equivalents for other languages, the API for this package should seem fairly familiar. If you’ve never written unit tests before, the PHPUnit API is simple to learn and use.

To fix this problem, we can install more using the command below.

sudo apt-get -y install phpunit

This command might take some time to finish depending on your machine internet connection.

You can also use apt command to install phpunit.

sudo apt -y install phpunit

Or if you have aptitude installed you can use the following command.

sudo aptitude install phpunit

Summary

In this tutorial we learn how to fix phpunit command not found error in Ubuntu / Debian / Kali Linux or Raspbian distribution.