How to start a composer from anywhere?

I just installed composer in my /usr/bin , so when I run php composer.phar from this folder, I get reference information about the composer. But, when I try to run the same from another folder, I get Could not open input file: composer.phar .

How to call php composer.phar from anywhere without problems?

+60
php composer-php
Jul 04 '12 at 17:17
source share
9 answers

composer.phar can run on its own, you do not need to prefix it with php . This should solve your problem (being in the difference of bash $ PATH and php include_path).

+46
Jul 04 '12 at 17:34
source share

You can perform a global installation :

Since Composer works with the current working directory, it can be installed in the system form.

  • Go to the directory in your path, for example cd /usr/local/bin
  • Get composer curl -sS https://getcomposer.org/installer | php curl -sS https://getcomposer.org/installer | php
  • Make phar chmod a+x composer.phar executable chmod a+x composer.phar executable
  • Go to the project directory cd /path/to/my/project
  • Use Composer, as usual, composer.phar install
  • If you wish, you can rename composer.phar to composer to simplify it.

Refresh . Sometimes you cannot or do not want to boot from /usr/local/bin (some of them have problems with user permissions or limited access), in which case you can try this

  • Open terminal
  • curl -sS http://getcomposer.org/installer | php -- --filename=composer
  • chmod a+x composer
  • sudo mv composer /usr/local/bin/composer
+83
May 18 '13 at 18:49
source share

How to run Composer from anywhere (on MacOS X) through a terminal

Background:

In fact, the getComposer website clearly states that, install Composer using the following curl command,

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

And that certainly does what he intended to do. And then he says to move the composer .phar to the / usr / local / bin / composer directory , and then the composer will be available worldwide, using the following command line in the terminal!

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

Question:

So the problem that leads me to google is that when I executed the above line in a Mac OS X terminal, it said Permission denied. For example:

 mv: rename composer.phar to /usr/local/bin/composer: Permission denied 

Answer:

After the link, I led me to a decision as a charm, and I am grateful for that. I just skipped the sudo command to the Move command line above. Now my Move command looks like this:

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

He directly invites you to authenticate and make sure that you are logged in. Therefore, if you enter a valid password, the move will be performed, and you can simply check if the composer is installed globally using the following line.

 composer about 

I hope this answer helped you expand your mind and finally solve your problem.

Hurrah!

+14
Mar 18 '15 at 7:58
source share

First install the composer as indicated in the installation documentation. I just added here for reference.

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

and then move the file to '/ usr / local / bin'.

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

Try running composer -V . If you get output like Composer version followed by a version number, the composer installs successfully.

If you get any output like composer: command not found , use the following command to create an alias for the composer. Thus, it will be executed worldwide.

alias composer='/usr/local/bin/composer'

Now, if you run composer -V , you will get the result as a Composer version followed by the version number.

Hope this helps someone.

+13
Apr 30 '15 at 5:11
source share

Just run this command to install the composer globally

 curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer 
+4
Oct 05 '15 at 8:45
source share

Just move it to the /usr/local/bin and delete the extension

 sudo mv composer.phar /usr/local/bin/composer 
+3
Feb 11 '17 at 11:55
source share

To run it from another location, you can use the composer program that came with the program. This is basically a bash script. If you don’t have it, you can create it by simply copying the following code into a text file

 #!/bin/sh dir=$(d=$(dirname "$0"); cd "$d" && pwd) if command -v 'cygpath' >/dev/null 2>&1; then dir=$(cygpath -m $dir); fi dir=$(echo $dir | sed 's/ /\ /g') php "${dir}/composer.phar" $* 

Then save the file inside the bin folder and name it composer without the file extension. Then add the bin folder to the environment variable f

+1
Jun 07 '13 at 5:08 on
source share

For MAC and LINUX, use the following procedure:

Add the directory where the .phar composer is located for you. PATH:

 export PATH=$PATH:/yourdirectory 

and then rename composer.phar to composer:

 mv composer.phar composer 
+1
Jan 12 '17 at 8:44
source share

You can make a simple global installation to run it from anywhere

 curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer 

This https://getcomposer.org/doc/00-intro.md#globally recommends. Works well on Ubuntu 14.04 without any problems. Thus, you do not need to do an example php compomser.phar show , you just run composer show in any directory you work with.

0
Mar 10 '15 at 8:33
source share



All Articles