How to Fix the “add-apt-repository: command not found” Error on Ubuntu
If you’re an Ubuntu user, you may have encountered the “add-apt-repository: command not found” error during an attempt to add a new repository to your system. This error occurs when the add-apt-repository command is not available in your system. Fortunately, this error can be fixed using a few simple steps.
- Install software-properties-common
The add-apt-repository command is a part of the software-properties-common package. Therefore, the first step is to make sure that this package is installed on your system.
To install software-properties-common, open a terminal window and type the following command:
“`
sudo apt-get update
sudo apt-get install software-properties-common
“`
Once the package is installed, you can try running the add-apt-repository command again. If the error persists, proceed to the next step.
- Install Python-software-properties
In some cases, the “add-apt-repository: command not found” error can also occur due to the absence of the python-software-properties package.
To install python-software-properties, open a terminal window and type the following command:
“`
sudo apt-get update
sudo apt-get install python-software-properties
“`
Once the package is installed, try running the add-apt-repository command again. The error should be resolved.
- Update Your System Path
If the first two methods don’t solve the issue, you can try adding the software path containing the add-apt-repository script to your system path.
Open the terminal and type:
“`
echo $PATH
“`
This command will list the system paths currently used.
Visit `/usr/lib/command-not-found` folder path in the terminal. Here, type `nano` command, followed by `command_not_found` file name.
“`
cd /usr/lib/command-not-found
sudo nano command_not_found
“`
Inside the file, locate the following line of code:
“`python
sys.stderr.write(_(“Can’t find ‘%s’
“`
Add the following line below this code:
“`
os.system(‘echo “+” >>/tmp/local-path’);
os.system(‘echo “export PATH=$PATH:/usr/sbin” >>/tmp/local-path’);
“`
This will add a new path to the default system path.
Once done, save the file, and exit.
Now type the command to update your system path:
“`
source /tmp/local-path
“`
Finally, try running the add-apt-repository command again. The error should be resolved.