简体   繁体   English

如何在 Mac 上安装 Composer?

[英]How to install Composer on a Mac?

I'm trying to get the Laravel PHP framework installed and for that I need to install Composer.我正在尝试安装 Laravel PHP 框架,为此我需要安装 Composer。 However I'm getting stuck there.但是我被困在那里。 I installed it before for Symfony but I couldn't get it to work so I think I deleted it.我之前为 Symfony 安装了它,但我无法让它工作,所以我想我删除了它。

When I open the terminal on Mac and enter one of the commands for installing composer like:当我在 Mac 上打开终端并输入用于安装 Composer 的命令之一,例如:

curl -sS https://getcomposer.org/installer | php

I get:我得到:

-bash: php: command not found
curl: (23) Failed writing body (0 != 1635)

Why is this?为什么是这样?

You can install it via Brew.您可以通过 Brew 安装它。

First, install Brew ;首先,安装Brew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then you can use Brew to install Composer;然后就可以使用Brew来安装Composer了;

brew install composer

That's it, it's now installed.就是这样,现在已经安装好了。 You can verify this by running composer --version您可以通过运行composer --version来验证这一点

  1. download file from https://getcomposer.org/installerhttps://getcomposer.org/installer下载文件

  2. execute the file执行文件

sudo php installer
  1. and move the file并移动文件
mv composer.phar /usr/local/bin/composer

Here it is:这里是:

curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

First install brew if not installed in Mac:如果未在 Mac 上安装,请先安装 brew:

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Update brew and install php and composer.更新 brew 并安装 php 和 composer。

$ brew update
$ brew install php
$ brew install composer

Verify by checking version:通过检查版本来验证:

 $ composer -V

I hope it helps.我希望它有帮助。

try尝试

~ which php
/usr/bin/php

curl -sS https://getcomposer.org/installer | /usr/bin/php

just open your terminal and follow this steps, here odbase is username of my mac.只需打开您的终端并按照以下步骤操作,这里的 odbase 是我的 mac 的用户名。

cd /Users/odbase/Downloads

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

php composer-setup.php

php -r "unlink('composer-setup.php');"

php composer.phar

mv composer.phar /usr/local/bin/composer 

(if this produce error please run with prefix sudo. {sudo mv composer.phar /usr/local/bin/composer}) (如果这会产生错误,请使用前缀 sudo 运行。{sudo mv composer.phar /usr/local/bin/composer})

installed for check安装检查

cd /usr/local/bin
ls

I deleted some files that I should not have deleted.我删除了一些我不应该删除的文件。 Did a repair install of OS X and now it works.做了 OS X 的修复安装,现在它可以工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM