如何在Ubuntu 20.04上安装Composer [快速入门]
介绍 (Introduction)
In this quickstart guide, we’ll install Composer on an Ubuntu 20.04 server.
在此快速入门指南中,我们将在Ubuntu 20.04服务器上安装Composer 。
For a more detailed version of this tutorial, with more explanations of each step, please refer to How To Install and Use Composer on Ubuntu 20.04.
有关本教程的更详细版本,以及每个步骤的更多说明,请参考如何在Ubuntu 20.04上安装和使用Composer 。
先决条件 (Prerequisites)
To follow this guide, you’ll need access to an Ubuntu 20.04 server as a sudo
user.
要遵循本指南,您需要以sudo
用户身份访问Ubuntu 20.04服务器。
第1步-安装依赖项 (Step 1 — Install Dependencies)
Start by updating your package manager cache and installing the required dependencies, including php-cli
:
首先更新包管理器缓存并安装所需的依赖项,包括php-cli
:
- sudo apt update sudo apt更新
- sudo apt install php-cli unzip 须藤apt install php-cli unzip
第2步-下载并安装Composer (Step 2 — Download and Install Composer)
Make sure you’re in your home directory, then retrieve the Composer installer using curl
:
确保您位于主目录中,然后使用curl
检索Composer安装程序 :
- cd ~ 光盘〜
- curl -sS https://getcomposer.org/installer -o composer-setup.php curl -sS https://getcomposer.org/installer -o composer-setup.php
Next, we’ll verify that the downloaded installer matches the SHA-384 hash for the latest installer found on the Composer Public Keys / Signatures page.
接下来,我们将验证下载的安装程序是否与Composer公钥/签名页面上找到的最新安装程序的SHA-384哈希匹配。
Using curl
, fetch the latest signature and store it in a shell variable:
使用curl
,获取最新的签名并将其存储在shell变量中:
- HASH=`curl -sS https://composer.github.io/installer.sig` HASH =`curl -sS https:// composer.github.io / installer.sig`
Now execute the following PHP code to verify that the installation script is safe to run:
现在执行以下PHP代码,以验证安装脚本可以安全运行:
- php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php -r“ if(hash_file('SHA384','composer-setup.php')==='$ HASH'){回声'安装程序已验证';}其他{回声'安装程序已损坏';取消链接('composer-setup .php');}回显PHP_EOL;“
You’ll see the following output:
您将看到以下输出:
Installer verified
Note: If the output says Installer corrupt
, you’ll need to repeat the download and verification process until you have a verified installer.
注意 :如果输出显示Installer corrupt
,则需要重复下载和验证过程,直到获得经过验证的安装程序为止。
The following command will download and install Composer as a system-wide command named composer
, under /usr/local/bin
:
以下命令将在/usr/local/bin
下以名为composer
的系统级命令下载并安装Composer:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
sudo php composer-setup.php --install-dir = / usr / local / bin --filename = composer
You’ll see output similar to this:
您将看到类似于以下的输出:
Output
All settings correct for using Composer
Downloading...
Composer (version 1.10.5) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
To test your installation, run:
要测试您的安装,请运行:
- composer 作曲家
Output
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.10.5 2020-04-10 11:44:22
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
--no-cache Prevent use of the cache
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
...
This verifies that Composer was successfully installed on your system and is available system-wide.
这将验证Composer已成功安装在您的系统上并且在系统范围内可用。
翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-composer-on-ubuntu-20-04-quickstart
更多推荐
所有评论(0)