Composer已安装,但得到 /usr/bin/env: php: No such file or directory

Composer installed, but get /usr/bin/env: php: No such file or directory

在 CentOS 7 上,我安装了 PHP 7.1.

然后我安装了作曲家:

cd /tmp
curl -sS https://getcomposer.org/installer | php71     --> used php71 instead of php, php didn't work
mv composer.phar /usr/local/bin/composer

然后,当使用 composer 时,我得到:

/usr/bin/env: php: No such file or directory

当使用 sudo composer 时,我得到:

sudo: composer: command not found

您需要将 /usr/local/bin 添加到 PATH 变量。最简单的方法是将其放入您的个人资料或位于以下任一位置的 bash_profile:

  • ~/.profile
  • ~/.bash_profile

您可以将以下内容添加到其中一个文件中:

export PATH="$PATH:/usr/local/bin/"

详情请见:https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

如果您在添加它时已登录,您可以强制Linux再次读取文件并使用source更新路径(一旦做出更改)bash提示:

source ~/.bash_profile

至于 php7php 的问题,正如 Alex 所建议的,您可以创建一个符号链接,这样它就可以像别名一样工作。

作为@alexhowansky suggested ,我运行以下命令:

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

现在 composer 命令可以使用了。

这对我有用 [Centos 7 with php 7.1] :
yum 安装 php71w-cli

您需要安装cli包。

yum install php71u-cli 是我需要做的 IUS php。

当您在本地安装了 composer 时会出现此问题。

要使其全局可执行,运行 在终端中执行以下命令,

sudo mv composer.phar /usr/bin/composer