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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43878731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 02:55:32  来源:igfitidea点击:

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

phpcentoscomposer-phpcentos7

提问by user3489502

On CentOS 7, I installed PHP 7.1.

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

Then I installed composer with:

然后我安装了composer:

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

Then, when using composer, I get:

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

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

When using sudo composer, I get:

使用时sudo composer,我得到:

sudo: composer: command not found

回答by user3489502

As @alexhowansky suggested, I ran the following command:

正如@alexhowansky 建议的那样,我运行了以下命令:

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

Now the composer command works. Thanks

现在 composer 命令可以工作了。谢谢

回答by Jeremy Harris

You need to add /usr/local/binto your PATHvariable. The easiest way is to throw it in your profile or bash_profile located at either:

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

  • ~/.profile
  • ~/.bash_profile
  • ~/.profile
  • ~/.bash_profile

You would add the following to one of those files:

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

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

For more details, see: https://unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

有关更多详细信息,请参阅:https: //unix.stackexchange.com/questions/26047/how-to-correctly-add-a-path-to-path

If you are logged in when you add it, you can force Linux to read the file again and update the path (once the changes are made) by using sourcefrom the bash prompt:

如果您在添加文件时已登录,则可以source在 bash 提示符下使用:

source ~/.bash_profile

As for the php7vs. phpissue, as Alex suggested, you can make a symlink so it works kinda like an alias.

至于php7vs.php问题,正如亚历克斯所建议的那样,您可以创建一个符号链接,使其有点像别名。

回答by Ari

This worked for me [Centos 7 with php 7.1] :
yum install php71w-cli

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

回答by fred

You need to install the cli package.

您需要安装 cli 包。

yum install php71u-cliis what I needed to do for IUS php.

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