Install composer globally

I did use below to install composer globally:
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
and it seems it is done. when I go under the folder where my composer.json is present to use:
$ composer update
or even if I want to do another action that has nothing to do with json like self-update I get:

[RuntimeException]
The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly

What should I do?

@nimasdj, are you using windows ?. Then just use the Composer-Setup.exe .

No, I am on *nix. what should I do?

Literally the first Google result is your solution.

Thanks. I use a ionCubed script and it denies auto_prepend_file. Is there any other trick to solve this? Otherwise I have to delete the global composer, how to delete it? Just deleting from /etc/lib/bin/composer is enough? Or do I need to clean something from elsewhere too as I installed it with sudo?

Instead of auto_prepend a file with putenv, can I set the environment in php.ini itself as I said the problem above? If yes how and if no how to delete it as I asked above?

In windows I tried this first in terminal or CMD.

Close your current terminal. Test usage with a new terminal:



C:\Users\username>composer -V

Composer version 27d8904

An advice yet?

My advice is to set one of those environment variables, so that composer can run correctly.

I’m sorry.

How to set those environments? I can’t use a file with putenv() then auto_prepend it in php.ini. Is there any other way to set those environments?

On a *NIX machine do the following.

Once on server goto current home directory:

$ cd ~

Create or edit the .bashrc file using vi or a editor of choice.

$ sudo vi .bashrc

Set environment variable in .bashrc file by wrtting the below line to the file.

export COMPOSER_HOME=/path/to/composer

Save file.

Exit terminal and login again.

Verify environment variable exists by issuing the following command.

echo $COMPOSER_HOME

disclaimer: I’m not nearly as proficient with the shell as I’m with application languages such as; php but I believe most of that to be correct.

in /root/.bashrc I added:

export COMPOSER_HOME=/usr/local/bin/.composer

but I get blank for

echo $COMPOSER_HOME

please advice.

did you log out and back into your terminal? Because… bashrc wont execute until you do.

This does not help.

Why are we making mountains out of molehills here folks? Just put the darn thing in /usr/local, which is already on the path.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.