On a server I want to do composer update/install and both give the error:
-bash: composer: command not found
I can see composer.phar, composer.json and composer.lock are there. How can I find out why I can’t update?
Unfortunately the site is down at the moment because I get an error because one package isn’t there at the moment.
UPDATE:
If I enter the following command:
php composer.phar install/update
everything seems to be working. Is there something I can do to change this or is it always necessary to enter the command this way?
halfer
19.7k17 gold badges95 silver badges183 bronze badges
asked Feb 2, 2017 at 21:08
1
Composer is probably not installed on your machine.
Run this in your terminal to get the latest Composer version (Source):
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Alternative way: https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos
hakre
189k51 gold badges426 silver badges824 bronze badges
answered Feb 2, 2017 at 21:16
Chin LeungChin Leung
14.4k3 gold badges31 silver badges55 bronze badges
3
Moved it to the suggested location:
mv composer.phar /usr/local/bin/composer
Still got “composer: command not found” when verifying the install?
Simply create a link to the /usr/bin location and voila!
sudo ln -s /usr/local/bin/composer /usr/bin/composer
answered Jul 6, 2021 at 15:33
YohanimYohanim
3,2277 gold badges50 silver badges90 bronze badges
0
If you are on Linux / Unix / macOS
You can do
mv composer.phar /usr/local/bin/composer
Note: If the above fails due to permissions, you may need to run it again with sudo.
Now run composer in order to run Composer instead of php composer.phar.
On Windows
you need to set the directory to your PATH environment variable if it isn’t already
answered May 1, 2021 at 0:22
Hussam KurdHussam Kurd
7,1582 gold badges42 silver badges38 bronze badges
1
Rename file located in /usr/local/bin
from composer.phar
to composer
answered Apr 30, 2021 at 23:43
1
- I set up an openserver
- I have installed Composer (Composer-Setup.exe)
On windows 10, I added the composer to the PATH environment variable. as in the photo.
I also found the composer.bat file and ran it.
(C:ProgramDataComposerSetupbincomposer.bat)
These steps helped me.
answered Jun 19, 2022 at 10:39
Brendan8cBrendan8c
3091 silver badge9 bronze badges
1
If you are on ubuntu and have already moved the file with the mv function but still get this error or you get an error like «Command ‘composer’ is available in ‘/usr/local/bin/composer'»
Try this to apply an alias as shown in the image below
Here is the command
alias composer='/usr/local/bin/composer'
screenshot of alias command
answered Jul 3, 2022 at 9:12
Composer is a dependency manager for PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them automatically. If you’re familiar with other programming languages, Composer is somewhat similar to Ruby’s bundler
, Node’s npm
or Python pip
.
Beginners sometimes encounter «composer: command not found» error message when they try to run Composer. This is a generic error and the real cause varies between different setups.
This article is going to show you a few common fixes to «composer: command not found» error.
If you receive the «composer: command not found» error, the composer
executable binary isn’t in one of the directories listed in your PATH
environment variable.
Typically, environment variables refer to variables accessible to all processes and users under the same Operating System (OS), such as Windows, macOS, and Linux. Environment variables, for instance, can be used to store systemwide values, such as PATH
, TEMP
or TMP
.
PATH
is the most popular and widely known environment variable, which stores a list of directories that contains files that can and should be executed.
Reinstall Composer
Often when a software does not work as intended, reinstalling it from scratch may be the way to go.
You don’t have to worry about system conflicts or reinstallation will overwrite anything , as «composer: command not found» indicates that the command is not recognized by the system.
The proper way to install Composer is to follow official documentation. Suppose you already have PHP on your system, run these commands in your
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
The first command downloads the installer script and saved as composer-setup.php
. The remaining commands compares compare the official hash against the one you downloaded, and run the file if no inconsistency found.
These commands will certainly be changed as new version releases every once in a while. You should copy them directly from Composer homepage.
Now composer
has been installed locally. If you want to install it globally, run the following command to move the composer.phar
executable to /usr/local/bin
.
sudo mv ./composer.phar /usr/bin/composer
Reinstall Composer with default arguments
If reinstalling Composer using official commands doesn’t work, you may try directly running composer-setup.php
with the default --install-dir
and --filename
argument.
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
The composer-setup.php
can be downloaded from https://getcomposer.org/installer.
Correct Composer executable path
As a few of our readers pointed out, sometimes, people follow installation guides online which puts its executable in /usr/local/bin/composer.phar
instead of /usr/local/bin/composer
.
Programs that expect composer
in /usr/local/bin/
or /usr/bin
would not be able to find it, therefore invoking the wrong command, causing bash
to raise «composer: command not found» error message. It has happened with Laravel users before.
One way to fix this is to create a symbolic link so that system calls to both path will run the same executable. Run these commands in any terminal window.
sudo ln -s /usr/local/bin/composer.phar /usr/local/bin/composer
sudo ln -s /usr/local/bin/composer.phar /usr/bin/composer
Alternatively, you can directly rename the executable by running
sudo mv /usr/local/bin/composer.phar /usr/local/bin/composer
sudo ln -s /usr/local/bin/composer.phar /usr/bin/composer
After that, you need to chmod
the original composer.phar
file and give it executable permission.
sudo chmod +x /usr/local/bin/composer.phar
Then, if you like, update the composer alias by running
alias composer="php /usr/local/bin/composer"
Windows users: Use Laragon
If you’re using Windows, you should replace the whole fragmented development stack with one portable development.
Laragon is a modern, maintained and rich-featured local development environment designed for PHP and Laravel programming. It’s equipped with a Laragon Terminal that is ready to use right out of the box, without setting up Composer separately.
На сервере я хочу обновить / установить композитор, и оба выдают ошибку:
-bash: composer: command not found
Я вижу, что там есть composer.phar, composer.json и composer.lock. Как я могу узнать, почему я не могу обновить?
К сожалению, сайт сейчас недоступен, потому что я получаю сообщение об ошибке, потому что в данный момент нет одного пакета.
ОБНОВИТЬ:
Если я введу следующую команду:
php composer.phar install/update
Кажется, все работает. Есть ли что-то, что я могу сделать, чтобы изменить это, или всегда нужно вводить команду таким образом?
1
Решение
Композитор, вероятно, не установлен на вашем компьютере.
Запустите это в своем терминале, чтобы получить последнюю версию Composer (Источник):
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"php composer-setup.php
php -r "unlink('composer-setup.php');"
Альтернативный способ: https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
1
Другие решения
Других решений пока нет …
From within the directory holding my composer.phar file, I can’t execute any composer commands.
I can see Composer is running when I execute
php composer.phar
But any direct composer statements fail.
Not sure if it matters but Composer was included within a cloned repository.
I just want to install a single Oauth library, then likely not touch Composer again for several months, so I don’t need to run it globally. I’m just confused why I can’t run Composer from within this directory.
7 Answers
This problem arises when you have composer installed locally.
To make it globally executable,run the below command in terminal
sudo mv composer.phar /usr/local/bin/composer
For CentOS 7 the command is
sudo mv composer.phar /usr/bin/composer
I am using CentOS and had same problem.
I changed /usr/local/bin/composer
to /usr/bin/composer
and it worked.
Run below command :
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
Verify Composer is installed or not
composer --version
Your composer.phar
command lacks the flag for executable, or it is not inside the path.
The first problem can be fixed with chmod +x composer.phar
, the second by calling it as ./composer.phar -v
.
You have to prefix executables that are not in the path with an explicit reference to the current path in Unix, in order to avoid going into a directory that has an executable file with an innocent name that looks like a regular command, but is not. Just think of a cat
in the current directory that does not list files, but deletes them.
The alternative, and better, fix for the second problem would be to put the composer.phar
file into a location that is mentioned in the path
This is for mac or ubuntu user, try this on terminal
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
or mac brew can try
brew install composer
Step 1 : Open Your terminal
Step 2 : Run bellow command
curl -sS https://getcomposer.org/installer | php
Step 3 : After installation run bellow command
sudo mv composer.phar /usr/local/bin/
Step 4 : Open bash_profile file create alias follow bellow steps
vim ~/.bash_profile
Step 5 : Add bellow line in bash_profile file
alias composer="php /usr/local/bin/composer.phar"
Step 6 : Close your terminal and reopen your terminal and run bellow command
composer
First I did alias setup on bash / zsh profile.
alias composer="php /usr/local/bin/composer.phar"
Then I moved composer.phar to /usr/local/bin/
cd /usr/local/bin
mv composer.phar composer
Then made composer executable by running
sudo chmod +x composer