问题
I tried to install composer via brew per:
In usr/local/bin
(which was not on Mavricks and I had to make personally) I did.
brew tap josegonzalez/homebrew-php
brew install josegonzalez/php/composer
I can run php composer.phar
, but when I do php composer.phar install
, I get the error:
Composer could not find a composer.json file in /usr/local/bin
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section
So I go to the https://getcomposer.org/doc/00-intro.md
. CTRL+F ".json" and nothing's there. Seriously composer?
EDIT:
What I was trying to do was to have composer
executable vs php composer.phar
. This works at this point from this now.
回答1:
The "Getting Started" page is the introduction to the documentation. Most documentation will start off with installation instructions, just like Composer's do.
The page that contains information on the composer.json
file is located here - under "Basic Usage", the second page.
I'd recommend reading over the documentation in full, so that you gain a better understanding of how to use Composer. I'd also recommend removing what you have and following the installation instructions provided in the documentation.
回答2:
To install composer and add to your global path:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
run these in terminal. It does say if you get an error that usr doesn't exist, you do need to manually make it. I know an answer was selected, so this is for anyone who may see this in the future, as i am sometimes, and don't want to be advised to visit yet another site. Its simple just two lines, might have to be in sudo if you have permission error
回答3:
Simple solution is install via this command :
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
To install package it's very simple :
composer global require "phpunit/php-invoker=1.1.*"
Ref : composer web site.
回答4:
In my case, I did not copy all project files to the folder where I was running composer install
. So do:
- Copy your project files (including the
composer.json
) to folder - open CMD (I am using ConEmu), navigate to the new folder, run
composer install
from there - It should work or throw errors in case the json file is not correct.
If you just want to make composer run, create a new composer.json
file with for example:
{
"require": {
"php": ">=5.3.2"
}
}
Then run composer install
.
回答5:
I encountered the same error, and was able to solve it as follows:
composer diagnose
to see if something is wrong with the version of composer installedcomposer self-update
to install the latest versioncomposer update
to update yourcomposer.json
file.
回答6:
In my case, I am using homestead. cd ~/Homestead
and run composer install
.
回答7:
You are in wrong directory. cd to your project directory then run composer update.
回答8:
- Create a file called composer.json
- Make sure the Composer can write in the directory you are looking for.
- Update your composer.
This worked for me
来源:https://stackoverflow.com/questions/31900211/composer-could-not-find-a-composer-json