作曲家: 未找到命令

在保存 comper.phar 文件的目录中,我不能执行任何作曲家命令。

我执行时可以看到 Composer 正在运行

php composer.phar

但任何直接的作曲家陈述都失败了。

不确定这是否重要,但 Composer 包含在一个克隆的存储库中。

我只想安装一个单独的 Oauth 库,然后可能几个月都不会再碰 Composer,所以我不需要在全球范围内运行它。我只是不明白为什么不能在这个目录中运行 Composer。

283765 次浏览

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 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

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

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

MacOS: composer is available on brew now (Tested on Php7+):

brew install composer

Install instructions on the Composer Docs page are quite to the point otherwise.

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

https://getcomposer.org/download/ it might help

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php

this code for ubuntu and wsl2.

Open terminal and run the following command,

sudo ln -s /usr/bin/php71 /usr/bin/php

Works in RHEL 8, php 7.4

sudo mv composer.phar /usr/bin/composer