如何在macOS上安装Composer?

28

我尝试在我的macOS版本:高山--> 10.13.4上安装Composer,但是在使用以下命令后:

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

它创建了一些文件和目录,但没有下载composer。我的终端显示以下错误:

未启用任何日志处理-使用stderr记录

已创建目录:/var/db/net-snmp

已创建目录:/var/db/net-snmp/mib_indexes`

我该怎么解决这个问题?

3个回答

67

旧回答(Ruby Homebrew安装程序现已被弃用,并已改写为Bash):

首先在您的MAC上安装Brew:

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

新答案:

首先在你的MAC上安装Brew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

然后安装PHP:

brew update
brew install php
brew install composer

测试安装,请运行:

 $ composer -V

2
显示错误:1. 错误:homebrew/dupes已被弃用。此存储库现在为空,因为其所有配方都已迁移。2. 错误:homebrew/php已被弃用。此存储库现在为空,因为其所有配方都已迁移。 - Abed Putra
homebrew/dupes现在已经成为核心的一部分了 - https://dev59.com/a6Pia4cB1Zd3GeqPy3eh 同样,homebrew/php也是如此 https://github.com/weprovide/valet-plus/issues/127 - Yorick
我在这些命令之上尝试了 composer update --ignore-platform-reqs,并且它起作用了。 - Mir Stephen

0
  1. 在Mac终端中安装Brew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  1. 安装Composer

brew install composer

  1. 检查Composer

composer -V


第三步应该是带有大写字母V的composer -V - Tim Rogers

-7
Install download the composer using the following curl  command in the 
terminal:

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

After the command, you will have composer.phar file in the current 
directory and the composer command is available as:

php composer.phar [composer commnad]

In order to make composer available globally, you have to move the 
recently downloaded composer.phar to local user’s bin folder as follow:

go to /usr/local/bin folder . You can click  Shift + Command + G to open 
the dialog to go to folder.

move the recently downloaded composer.phar in the usr/local/bin folder
create a alias using command  alias composer="php 
 /usr/local/bin/composer.phar"


Now, you can access the composer from the terminal simply using the 
composer  command. Thats it.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接