安装相关工具

确保在您的Debian或Ubuntu服务器(14.04 LTS或更早版本)上安装了curl和php-cli,curl及其相关工具:

$ sudo apt-get install curl php5-cli git

如果您使用的是Ubuntu Linux 16.04 LTS或更高版本,按照PHP 7.x。

$ sudo apt install curl php7.0-cli git

安装composer工具

在/usr/local/bin /目录下安装composer:

$ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

验证composer

$ /usr/local/bin/composer

输出示例:

______
  / ____/___  ____ ___  ____  ____  ________  _____
/ /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.0-dev (1c525b76f81123af180743d31c208c29351cf931) 2015-12-09 15:47:26
 
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
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 
Available commands:
  about           Short information about Composer
  archive         Create an archive of this composer package
  browse          Opens the package's repository URL or homepage in your browser.
  clear-cache     Clears composer's internal package cache.
  clearcache      Clears composer's internal package cache.
  config          Set config options
  create-project  Create new project from a package into given directory.
  depends         Shows which packages depend on the given package
  diagnose        Diagnoses the system to identify common errors.
  dump-autoload   Dumps the autoloader
  dumpautoload    Dumps the autoloader
  global          Allows running commands in the global composer dir ($COMPOSER_HOME).
  help            Displays help for a command
  home            Opens the package's repository URL or homepage in your browser.
  info            Show information about packages
  init            Creates a basic composer.json file in current directory.
  install         Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses        Show information about licenses of dependencies
  lint            Run the lint script as defined in composer.json.
  list            Lists commands
  phpcs           Run the phpcs script as defined in composer.json.
  remove          Removes a package from the require or require-dev
  require         Adds required packages to your composer.json and installs them
  run-script      Run the scripts defined in composer.json.
  search          Search for packages
  self-update     Updates composer.phar to the latest version.
  selfupdate      Updates composer.phar to the latest version.
  show            Show information about packages
  status          Show a list of locally modified packages
  suggests        Show package suggestions
  test            Run the test script as defined in composer.json.
  update          Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate        Validates a composer.json and composer.lock

如何安装在composer.json文件中定义的依赖项?

只需执行以下命令即可下载并安装您的应用程序/项目的所有依赖项:

$ composer install

如何更新composer.lock文件?

如果没有.lock文件,则此工具将根据.json文件中的依赖关系创建一个文件。

如果您已有一个composer.lock文件,则需要按以下方式运行它:

$ composer update
如何在Debian/Ubuntu Linux上安装Composer

运行composer命令报错:

Error: your composer.lock file is not up to date, run composer update to install newer dependencies

如何在Debian或Linux上为PHP安装composer命令?
在Debian/Ubuntu Linux上如何安装和使用Composer?

Composer是PHP的依赖项管理器工具。用于为项目安装和更新库。
有许多使用php编写的开源项目和框架,都使用Composer来管理和安装它们的软件包和依赖项。

日期:2020-03-23 08:03:54 来源:oir作者:oir