Ubuntu環境下,如何手動安裝Composer
測試環境
撰寫本文時,測試的環境是
「Xubuntu 14.04 64位元」
前置作業
確保已經有安裝「php5-cli」這個套件。
1 |
$ sudo apt-get install php5-cli |
一般安裝
一般可以參照「這一頁」來安裝。
執行
1 |
$ curl -sS https://getcomposer.org/installer | php |
或是執行
1 |
$ php -r "readfile('https://getcomposer.org/installer');" | php |
或是執行 (安裝到「~/bin」範例)
1 2 3 4 |
# install to ~/bin cd ~ mkdir bin -p curl -sS https://getcomposer.org/installer | php -- --install-dir=bin --filename=composer |
手動安裝
這篇主要是要介紹手動安裝的方式。
下載最新的「composer.phar」。
1 |
$ wget -c https://getcomposer.org/composer.phar |
設為可執行
1 |
$ chmod u+x composer.phar |
放到「~/bin」這個這個資料夾底下,並且重新命名為「composer」。
1 |
$ mv composer.phar ~/bin/composer |
測試看看
1 |
$ composer |
就會看到
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/ Composer version 1.0-dev (8d6ab70ae590e84cc94871a3ee08be2b09979520) 2015-02-01 14:00:06 Usage: [options] command [arguments] Options: --help (-h) Display this help message. --quiet (-q) Do not output any message. --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug. --version (-V) Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction (-n) Do not ask any interactive question. --profile Display timing and memory usage information --working-dir (-d) If specified, use the given directory as working directory. 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 list Lists commands 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 update Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file. validate Validates a composer.json |
觀看版本
可以執行
1 |
$ composer --version |
或是執行
1 |
$ composer -V |
可以看到
1 |
Composer version 1.0-dev (8d6ab70ae590e84cc94871a3ee08be2b09979520) 2015-02-01 14:00:06 |
更新版本
未來要更新版本,
只要執行
1 |
$ composer self-update |
或是執行
1 |
$ composer selfupdate |
若已經是最新的版本,就會看到類似下面的訊息
1 |
You are already using composer version 8d6ab70ae590e84cc94871a3ee08be2b09979520. |
說明為什麼可以安裝在「~/bin」
觀看「~/.profile」。
1 |
$ cat ~/.profile |
一般的狀況下,Ubuntu的「~/.profile」如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login # exists. # see /usr/share/doc/bash/examples/startup-files for examples. # the files are located in the bash-doc package. # the default umask is set in /etc/profile; for setting the umask # for ssh logins, install and configure the libpam-umask package. #umask 022 # if running bash if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then . "$HOME/.bashrc" fi fi # set PATH so it includes user's private bin if it exists if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi |
也就是說,預設會將「~/bin」設定到「PATH」。
0 Comments