How to Install Composer in Linux Ubuntu 18.04 Bionic Beaver

Posted on

This article will show how to install composer in Linux Ubuntu operating system distribution. Precisely, it is in the Linux Ubuntu 18.04 Bionic Beaver. First of all, the most important thing is to know about composer. It is a tool acts as a dependency manager for PHP.  This tool will manage the dependencies you require on a PHP project by a project basis. All of the all the required libraries, dependencies and is in the area of composer for further manage by pulling them and place it all in one place. The following are the steps in order to install composer :

1. Switch to the root account if it is necessary. But if it not, the command for installing composer will still works with another account. Don’t forget to use ‘sudo’ for executing the command with a non-root account. Below is the command execution :

sudo apt -y install composer

Before moving forward to the installation process, just check the availability of the tool or program in the operating system. Type the following command to ensure whether or not the tool or program exist :

user@hostname:~$ apt list --installed | grep composer

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

composer/bionic,bionic,now 1.6.3-1 all [installed]
php-composer-ca-bundle/bionic,bionic,now 1.1.0-1 all [installed,automatic]
php-composer-semver/bionic,bionic,now 1.4.2-1 all [installed,automatic]
php-composer-spdx-licenses/bionic,bionic,now 1.3.0-1 all [installed,automatic]

According to the output above, the tool or program with the name of ‘composer’ is available. But if it is not exist, using the above command pattern, the following is the command execution :

user@hostname:/var/www/html$ sudo apt -y install composer
[sudo] password for user: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  jsonlint php-cli-prompt php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses php-json-schema php-psr-log php-symfony-console php-symfony-debug php-symfony-filesystem
  php-symfony-finder php-symfony-polyfill-mbstring php-symfony-process
Suggested packages:
  fossil mercurial subversion php-zip php-symfony-event-dispatcher php-symfony-lock
The following NEW packages will be installed:
  composer jsonlint php-cli-prompt php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses php-json-schema php-psr-log php-symfony-console php-symfony-debug php-symfony-filesystem
  php-symfony-finder php-symfony-polyfill-mbstring php-symfony-process
0 upgraded, 14 newly installed, 0 to remove and 3 not upgraded.
Need to get 586 kB of archives.
After this operation, 3.482 kB of additional disk space will be used.
Get:1 bionic/universe amd64 php-json-schema all 5.2.6-1 [32,5 kB]
Get:2 bionic/universe amd64 php-composer-ca-bundle all 1.1.0-1 [13,7 kB]
Get:3 bionic/universe amd64 php-composer-semver all 1.4.2-1 [10,6 kB]
Get:4 bionic/universe amd64 php-composer-spdx-licenses all 1.3.0-1 [10,4 kB]
Get:5 bionic/universe amd64 jsonlint all 1.7.1-1 [11,2 kB]
Get:6 bionic/universe amd64 php-symfony-polyfill-mbstring all 1.6.0-2 [12,1 kB]
Get:7 bionic/universe amd64 php-psr-log all 1.0.2-1 [6.976 B]
Get:8 bionic-updates/universe amd64 php-symfony-debug all 3.4.6+dfsg-1ubuntu0.1 [36,4 kB]                                                                              
Get:9 bionic-updates/universe amd64 php-symfony-console all 3.4.6+dfsg-1ubuntu0.1 [65,6 kB]                                                                            
Get:10 bionic-updates/universe amd64 php-symfony-finder all 3.4.6+dfsg-1ubuntu0.1 [21,9 kB]                                                                            
Get:11 bionic-updates/universe amd64 php-symfony-process all 3.4.6+dfsg-1ubuntu0.1 [28,8 kB]                                                                           
Get:12 bionic-updates/universe amd64 php-symfony-filesystem all 3.4.6+dfsg-1ubuntu0.1 [18,7 kB]                                                                        
Get:13 bionic/universe amd64 php-cli-prompt all 1.0.3+dfsg-1 [4.620 B]                                                                                                 
Get:14 bionic/universe amd64 composer all 1.6.3-1 [313 kB]                                                                                                             
Fetched 586 kB in 17s (34,6 kB/s)                                                                                                                                                                          
Selecting previously unselected package php-json-schema.
(Reading database ... 273588 files and directories currently installed.)
Preparing to unpack .../00-php-json-schema_5.2.6-1_all.deb ...
Unpacking php-json-schema (5.2.6-1) ...
Selecting previously unselected package php-composer-ca-bundle.
Preparing to unpack .../01-php-composer-ca-bundle_1.1.0-1_all.deb ...
Unpacking php-composer-ca-bundle (1.1.0-1) ...
Selecting previously unselected package php-composer-semver.
Preparing to unpack .../02-php-composer-semver_1.4.2-1_all.deb ...
Unpacking php-composer-semver (1.4.2-1) ...
Selecting previously unselected package php-composer-spdx-licenses.
Preparing to unpack .../03-php-composer-spdx-licenses_1.3.0-1_all.deb ...
Unpacking php-composer-spdx-licenses (1.3.0-1) ...
Selecting previously unselected package jsonlint.
Preparing to unpack .../04-jsonlint_1.7.1-1_all.deb ...
Unpacking jsonlint (1.7.1-1) ...
Selecting previously unselected package php-symfony-polyfill-mbstring.
Preparing to unpack .../05-php-symfony-polyfill-mbstring_1.6.0-2_all.deb ...
Unpacking php-symfony-polyfill-mbstring (1.6.0-2) ...
Selecting previously unselected package php-psr-log.
Preparing to unpack .../06-php-psr-log_1.0.2-1_all.deb ...
Unpacking php-psr-log (1.0.2-1) ...
Selecting previously unselected package php-symfony-debug.
Preparing to unpack .../07-php-symfony-debug_3.4.6+dfsg-1ubuntu0.1_all.deb ...
Unpacking php-symfony-debug (3.4.6+dfsg-1ubuntu0.1) ...
Selecting previously unselected package php-symfony-console.
Preparing to unpack .../08-php-symfony-console_3.4.6+dfsg-1ubuntu0.1_all.deb ...
Unpacking php-symfony-console (3.4.6+dfsg-1ubuntu0.1) ...
Selecting previously unselected package php-symfony-finder.
Preparing to unpack .../09-php-symfony-finder_3.4.6+dfsg-1ubuntu0.1_all.deb ...
Unpacking php-symfony-finder (3.4.6+dfsg-1ubuntu0.1) ...
Selecting previously unselected package php-symfony-process.
Preparing to unpack .../10-php-symfony-process_3.4.6+dfsg-1ubuntu0.1_all.deb ...
Unpacking php-symfony-process (3.4.6+dfsg-1ubuntu0.1) ...
Selecting previously unselected package php-symfony-filesystem.
Preparing to unpack .../11-php-symfony-filesystem_3.4.6+dfsg-1ubuntu0.1_all.deb ...
Unpacking php-symfony-filesystem (3.4.6+dfsg-1ubuntu0.1) ...
Selecting previously unselected package php-cli-prompt.
Preparing to unpack .../12-php-cli-prompt_1.0.3+dfsg-1_all.deb ...
Unpacking php-cli-prompt (1.0.3+dfsg-1) ...
Selecting previously unselected package composer.
Preparing to unpack .../13-composer_1.6.3-1_all.deb ...
Unpacking composer (1.6.3-1) ...
Setting up php-psr-log (1.0.2-1) ...
Setting up php-symfony-finder (3.4.6+dfsg-1ubuntu0.1) ...
Setting up php-composer-ca-bundle (1.1.0-1) ...
Setting up php-json-schema (5.2.6-1) ...
Setting up php-composer-semver (1.4.2-1) ...
Setting up php-cli-prompt (1.0.3+dfsg-1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up php-composer-spdx-licenses (1.3.0-1) ...
Setting up php-symfony-filesystem (3.4.6+dfsg-1ubuntu0.1) ...
Setting up php-symfony-polyfill-mbstring (1.6.0-2) ...
Setting up jsonlint (1.7.1-1) ...
Setting up php-symfony-process (3.4.6+dfsg-1ubuntu0.1) ...
Setting up php-symfony-debug (3.4.6+dfsg-1ubuntu0.1) ...
Setting up php-symfony-console (3.4.6+dfsg-1ubuntu0.1) ...
Setting up composer (1.6.3-1) ...

2. Test the command. Below is the command execution of ‘composer’ :

user@hostname:~$ composer
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
Composer 1.6.3 2018-01-31 16:28:17

  command [options] [arguments]

  -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.
  -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                Shows the short information about Composer.
  archive              Creates an archive of this composer package.
  browse               [home] Opens the package's repository URL or homepage in your browser.
  check-platform-reqs  Check that platform requirements are satisfied.
  clear-cache          [clearcache] Clears composer's internal package cache.
  config               Sets config options.
  create-project       Creates new project from a package into given directory.
  depends              [why] Shows which packages cause the given package to be installed.
  diagnose             Diagnoses the system to identify common errors.
  dump-autoload        [dumpautoload] Dumps the autoloader.
  exec                 Executes a vendored binary/script.
  global               Allows running commands in the global composer dir ($COMPOSER_HOME).
  help                 Displays help for a command
  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             Shows information about licenses of dependencies.
  list                 Lists commands
  outdated             Shows a list of installed packages that have updates available, including their latest version.
  prohibits            [why-not] Shows which packages prevent the given package from being installed.
  remove               Removes a package from the require or require-dev.
  require              Adds required packages to your composer.json and installs them.
  run-script           Runs the scripts defined in composer.json.
  search               Searches for packages.
  show                 [info] Shows information about packages.
  status               Shows a list of locally modified packages.
  suggests             Shows package suggestions.
  update               [upgrade] Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate             Validates a composer.json and composer.lock.

One thought on “How to Install Composer in Linux Ubuntu 18.04 Bionic Beaver

Leave a Reply