add-apt-repository is broken with non-UTF-8 locales
I'm trying to install PHP version 7.4 with NGINX, and I'm getting the following error when trying to add a repository:
sudo add-apt-repository ppa:USER/php Co-installable PHP versions: PHP 5.6, PHP 7.x and most requested extensions are included. Only Supported Versions of PHP (http://php.net/supported-versions.php) for Supported Ubuntu Releases (https://wiki.ubuntu.com/Releases) are provided. Don't ask for end-of-life PHP versions or Ubuntu release, they won't be provided. Debian oldstable and stable packages are provided as well: https://deb.sury.org/#debian-dpa You can get more information about the packages at https://deb.sury.org IMPORTANT: The <foo>-backports is now required on older Ubuntu releases.</foo> BUGS&FEATURES: This PPA now has a issue tracker: https://deb.sury.org/#bug-reporting CAVEATS: If you are using php-gearman, you need to add ppa:USER/pkg-gearman If you are using apache2, you are advised to add ppa:USER/apache2 If you are using nginx, you are advised to add ppa:USER/nginx-mainline or ppa:USER/nginx PLEASE READ: If you like my work and want to give me a little motivation, please consider donating regularly: https://donate.sury.org/ WARNING: add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56 for workaround: LC_ALL=C.UTF-8 add-apt-repository ppa:USER/php More info: https://launchpad.net/~USER/+archive/ubuntu/php Press [ENTER] to continue or ctrl-c to cancel adding it Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 688, in addkey_func func(**kwargs) File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 386, in add_key return apsk.add_ppa_signing_key() File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 252, in add_ppa_signing_key tmp_keyring, tmp_secret_keyring, signing_key_fingerprint, tmp_keyring_dir): File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 181, in _recv_key "--recv", signing_key_fingerprint, File "/usr/lib/python3.7/subprocess.py", line 323, in call with Popen(*popenargs, **kwargs) as p: File "/usr/lib/python3.7/subprocess.py", line 775, in init restore_signals, start_new_session) File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: 'gpg': 'gpg'
If you navigate to the github discussion linked in the error message
(https://github.com/oerdnj/deb.sury.org/issues/56), you can see that some other users were able to work around this by installing or upgrading their server's language packages.
I wasn't able to recreate the issue myself, but it looks like the first user was able to take the following steps to do just that:
apt-get update && apt-get install -y language-pack-en-base && export LC_ALL=en_US.UTF-8 && export LANG=en_US.UTF-8 && apt-get install -y software-properties-common && add-apt-repository -y ppa:ondrej/php5-5.6 && add-apt-repository -y ppa:ondrej/mariadb-10.0 && apt-get update && apt-get -y upgrade
Another user was able to simply set their language to UTF-8:
locale-gen en_US.UTF-8 export LANG=en_US.UTF-8 export LC_ALL=en_US.UTF-8
Just in case, here's a guide on installing PHP 7.4 on Ubuntu for reference: How To Install PHP 7.4 on Ubuntu 20.04/18.04/16.04