## 添加源
Ubuntu 18 之前的版本官方不提供源,需使用第三方源
```
sudo add-apt-repository ppa:jczaplicki/xenial-php74-temp
```
Ubuntu 18 及以上版本使用
```
sudo add-apt-repository ppa:ondrej/php
```
如果遇到错误 UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 92 则使用下面的命令添加源。
```
LC_ALL=C.UTF-8 add-apt-repository ppa:jczaplicki/xenial-php74-temp
```
## 安装新版本
```
sudo apt-get update
sudo apt install -y php7.4-cli php7.4-dev php7.4-pgsql php7.4-sqlite3 php7.4-gd php7.4-curl php7.4-memcached php7.4-imap php7.4-mysql php7.4-mbstring php7.4-xml php7.4-zip php7.4-bcmath php7.4-soap php7.4-intl php7.4-readline php7.4-pcov php7.4-msgpack php7.4-igbinary php7.4-ldap php7.4-redis php7.4
php -v
```
## 卸载旧版本(可选)
```
sudo apt purge php7.3 libapache2-mod-php7.3 # For removing PHP 7.3
sudo apt purge php7.2 libapache2-mod-php7.2 # For removing PHP 7.2
sudo apt purge php7.1 libapache2-mod-php7.1 # For removing PHP 7.1
sudo apt purge php7.0 libapache2-mod-php7.0 # For removing PHP 7.0
```