How to Install Composer in Linux Ubuntu 19.10 Operating System

Posted on

This is an article where the main content is showing how to install a composer tool in Linux Ubuntu 19.10 operating system. What is a composer tool actually ?. According to the information exist in this link, it is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. So, it is very important upon developing a system or an application powered by PHP programming language. The following is the installation step for Composer in a Linux Ubuntu 19.10 operating system :

1. First of all, switch to ‘root’ or ‘admin’ user account. In order to switch user account, there is a utility called ‘sudo’ in Linux Ubuntu. So, execute the ‘sudo’ command for switching to ‘root’ or ‘admin’ user account as follows :

user@hostname:~$ sudo su - 
[sudo] password for user: 
root@hostname:~# 

2. Next, just execute a command for installing composer. Execute the command in the command line interface as follows :

root@hostname:/var/www/html# apt -y install composer
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  jsonlint php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses php-composer-xdebug-handler php-json-schema php-psr-container php-psr-log php-symfony-console php-symfony-filesystem
  php-symfony-finder php-symfony-process php-symfony-service-contracts
Suggested packages:
  fossil mercurial subversion php-symfony-event-dispatcher php-symfony-lock php-symfony-service-implementation
The following NEW packages will be installed:
  composer jsonlint php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses php-composer-xdebug-handler php-json-schema php-psr-container php-psr-log php-symfony-console
  php-symfony-filesystem php-symfony-finder php-symfony-process php-symfony-service-contracts
0 upgraded, 14 newly installed, 0 to remove and 0 not upgraded.
Need to get 569 kB of archives.
After this operation, 3.379 kB of additional disk space will be used.
Get:1 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-composer-ca-bundle all 1.2.3-1 [9.336 B]
Get:2 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-composer-semver all 1.5.0-2 [10,9 kB]
Get:3 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-composer-spdx-licenses all 1.5.2-1 [11,2 kB]
Get:4 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-psr-log all 1.1.0-1 [8.032 B]
Get:5 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-composer-xdebug-handler all 1.3.3-2 [14,2 kB]
Get:6 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-json-schema all 5.2.8-1 [32,2 kB]
Get:7 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 jsonlint all 1.7.1-1 [11,2 kB]
Get:8 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-psr-container all 1.0.0-1 [3.180 B]
Get:9 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-symfony-service-contracts all 1.1.6-1 [7.084 B]
Get:10 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-symfony-console all 4.3.4+dfsg-1ubuntu1 [71,1 kB]
Get:11 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-symfony-filesystem all 4.3.4+dfsg-1ubuntu1 [17,9 kB]
Get:12 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-symfony-finder all 4.3.4+dfsg-1ubuntu1 [22,7 kB]
Get:13 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 php-symfony-process all 4.3.4+dfsg-1ubuntu1 [27,1 kB]
Get:14 http://xxxxxxxxxxxxxxxxxxxxxxxxxxxx eoan/universe amd64 composer all 1.9.0-2 [323 kB]
Fetched 569 kB in 4s (160 kB/s)    
Selecting previously unselected package php-composer-ca-bundle.
(Reading database ... 203452 files and directories currently installed.)
Preparing to unpack .../00-php-composer-ca-bundle_1.2.3-1_all.deb ...
Unpacking php-composer-ca-bundle (1.2.3-1) ...
Selecting previously unselected package php-composer-semver.
Preparing to unpack .../01-php-composer-semver_1.5.0-2_all.deb ...
Unpacking php-composer-semver (1.5.0-2) ...
Selecting previously unselected package php-composer-spdx-licenses.
Preparing to unpack .../02-php-composer-spdx-licenses_1.5.2-1_all.deb ...
Unpacking php-composer-spdx-licenses (1.5.2-1) ...
Selecting previously unselected package php-psr-log.
Preparing to unpack .../03-php-psr-log_1.1.0-1_all.deb ...
Unpacking php-psr-log (1.1.0-1) ...
Selecting previously unselected package php-composer-xdebug-handler.
Preparing to unpack .../04-php-composer-xdebug-handler_1.3.3-2_all.deb ...
Unpacking php-composer-xdebug-handler (1.3.3-2) ...
Selecting previously unselected package php-json-schema.
Preparing to unpack .../05-php-json-schema_5.2.8-1_all.deb ...
Unpacking php-json-schema (5.2.8-1) ...
Selecting previously unselected package jsonlint.
Preparing to unpack .../06-jsonlint_1.7.1-1_all.deb ...
Unpacking jsonlint (1.7.1-1) ...
Selecting previously unselected package php-psr-container.
Preparing to unpack .../07-php-psr-container_1.0.0-1_all.deb ...
Unpacking php-psr-container (1.0.0-1) ...
Selecting previously unselected package php-symfony-service-contracts.
Preparing to unpack .../08-php-symfony-service-contracts_1.1.6-1_all.deb ...
Unpacking php-symfony-service-contracts (1.1.6-1) ...
Selecting previously unselected package php-symfony-console.
Preparing to unpack .../09-php-symfony-console_4.3.4+dfsg-1ubuntu1_all.deb ...
Unpacking php-symfony-console (4.3.4+dfsg-1ubuntu1) ...
Selecting previously unselected package php-symfony-filesystem.
Preparing to unpack .../10-php-symfony-filesystem_4.3.4+dfsg-1ubuntu1_all.deb ...
Unpacking php-symfony-filesystem (4.3.4+dfsg-1ubuntu1) ...
Selecting previously unselected package php-symfony-finder.
Preparing to unpack .../11-php-symfony-finder_4.3.4+dfsg-1ubuntu1_all.deb ...
Unpacking php-symfony-finder (4.3.4+dfsg-1ubuntu1) ...
Selecting previously unselected package php-symfony-process.
Preparing to unpack .../12-php-symfony-process_4.3.4+dfsg-1ubuntu1_all.deb ...
Unpacking php-symfony-process (4.3.4+dfsg-1ubuntu1) ...
Selecting previously unselected package composer.
Preparing to unpack .../13-composer_1.9.0-2_all.deb ...
Unpacking composer (1.9.0-2) ...
Setting up php-symfony-finder (4.3.4+dfsg-1ubuntu1) ...
Setting up jsonlint (1.7.1-1) ...
Setting up php-psr-container (1.0.0-1) ...
Setting up php-symfony-service-contracts (1.1.6-1) ...
Setting up php-composer-ca-bundle (1.2.3-1) ...
Setting up php-symfony-process (4.3.4+dfsg-1ubuntu1) ...
Setting up php-symfony-filesystem (4.3.4+dfsg-1ubuntu1) ...
Setting up php-psr-log (1.1.0-1) ...
Setting up php-composer-semver (1.5.0-2) ...
Setting up php-json-schema (5.2.8-1) ...
Setting up php-composer-spdx-licenses (1.5.2-1) ...
Setting up php-symfony-console (4.3.4+dfsg-1ubuntu1) ...
Setting up php-composer-xdebug-handler (1.3.3-2) ...
Setting up composer (1.9.0-2) ...
Processing triggers for man-db (2.8.7-3) ...
root@hostname:/var/www/html# 

3. After that, just execute the ‘composer’ command in the command line interface as follows :

root@hostname:~# composer 
Do not run Composer as root/super user! See https://getcomposer.org/root for details
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer 1.9.0 2019-08-02 20:55:32
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
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              [i] 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           [run] 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, for packages installed from source.
  suggests             Shows package suggestions.
  update               [u|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.
root@hostname:~#

As in the above output command execution, there is a message informing to not use ‘root’ account while executing the ‘composer’ command.

4. Following the above command execution, in order to get the version of the composer, just execute the following command :

root@hostname:~# composer --version
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Composer 1.9.0 2019-08-02 20:55:32
root@hostname:~# 

Finally, the ‘composer’ tool is available for further usage in Linux Ubuntu 19.10 operating system.

Leave a Reply