How to install Composer globally in linux?

4

Generally, when I install Composer, I usually do this:

curl -sS https://getcomposer.org/installer | php  

It downloads a file called composer.phar . But then I have to keep putting the folder path all the time I'm going to execute.

For example:

~/downloads/composer.phar 

I'd like to do this simply on the command line:

 composer self-update && composer update

How can I do this in Linux?

    
asked by anonymous 16.03.2016 / 15:26

3 answers

5

Aliases

An alias could solve

vi ~/.bashrc

add

alias nome_do_alias=comando

example

alias composer=/a/pasta/onde/estah/conposer.phar

The alias feature varies according to the Linux distribution, but in general it is similar to the example above.

Symbolic link

Another even simpler way is to create a symbolic link

ln -s /local/do/arquivo/composer.phar composer

    
16.03.2016 / 16:55
7

The solution to this is to just move the downloaded file to the /usr/local/bin folder.

Come on.

1) First download the composer file:

curl -sS https://getcomposer.org/installer | php  

2) I believe that before moving it is only necessary to give permission to execute:

 sudo chmod +x composer.phar

3) And then, just move it:

sudo mv composer.phar /usr/local/bin/composer

Font : Install Composer on Linux and Mac OS X

If you do not have curl installed, you can run the command:

 sudo apt-get install curl

Or use one of these instead of the first step:

php -r "readfile('https://getcomposer.org/installer');" | php

Or

wget https://getcomposer.org/composer.phar 
    
16.03.2016 / 15:28
5

First, download the composer installer in any folder:

curl -sS https://getcomposer.org/installer | php

Next, use the mv command to move the composer file to the folder where linux recognizes commands:

mv composer.phar /usr/local/bin/composer

Here you can use the terminal

composer install ...
    
16.03.2016 / 15:33