How to install Composer globally on linux?

Asked

Viewed 6,502 times

4

Usually, when we install Composer, I usually do so:

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

It downloads a file called composer.phar. But then I have to keep putting the path of the folder every time I run.

For example:

~/downloads/composer.phar 

I’d like to do just that on the command line:

 composer self-update && composer update

How can I do this on Linux?

3 answers

8

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

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 execution permission:

 sudo chmod +x composer.phar

3) And then, just move it:

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

Source: Install Composer on Linux and Mac OS X

If you don’t have the curl installed, you can run the command:

 sudo apt-get install curl

Or use one of these options instead of the first step:

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

Or

wget https://getcomposer.org/composer.phar 
  • wget https://getcomposer.org/composer.phar will download in user folder, no?

  • Yes, but then it moves after downloading. As I said, it is a replacement of the first step.

  • Oh it’s true, I’ve traveled, I use Debian, and there "can’t stand" sudo, we make use of su which brings us to root’s "user folder" :)

  • I managed to install the Composer, worth :D

5

First, download the installer of Composer in any folder:

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

Then use the command mv to move the Composer file to the folder where linux recognizes the commands:

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

There you can use in the terminal

composer install ...

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 overall is similar to the above example.

Symbolic link

Another even simpler way is to create a Symbolic link

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

  • 1

    Good alternative ;)

  • I’m gonna use this one!

  • Really, this is better. If you have to update with self-update, would not have permission problems (happened this on our semi-dedicated server, I do not have access to sudo)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.