如何获取所有已安装软件包的列表以及composer中的版本?


258

我一直在使用本地计算机上使用Symfony 2.1的项目。我已经将其上载到服务器,但是当我尝试使用Composer安装供应商捆绑包时,出现了很多依赖关系错误。大概这与刚刚发布的最新版本的Symfony和我的composer.json文件未指定确切的版本号有关。

有什么方法可以快速显示本地计算机上所有内容的版本号?

这是我的composer.json文件(直到几天前都可以正常工作):

{
    "name": "symfony/framework-standard-edition",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.1.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.0.*",
        "twig/extensions": "1.0.*",
        "symfony/assetic-bundle": "2.1.*",
        "symfony/swiftmailer-bundle": "2.1.*",
        "symfony/monolog-bundle": "2.1.*",
        "sensio/distribution-bundle": "2.1.*",
        "sensio/framework-extra-bundle": "2.1.*",
        "sensio/generator-bundle": "2.1.*",
        "jms/security-extra-bundle": "1.2.*",
        "jms/di-extra-bundle": "1.1.*",
        "sonata-project/admin-bundle": "*",
        "sonata-project/cache-bundle": "dev-master",
        "sonata-project/doctrine-orm-admin-bundle": "dev-master",
        "stof/doctrine-extensions-bundle": "1.1.x-dev",
        "sonata-project/user-bundle": "dev-master",
        "sonata-project/easy-extends-bundle": "dev-master",
        "friendsofsymfony/user-bundle": "2.0.x-dev",
        "friendsofsymfony/jsrouting-bundle": "*",
        "liip/imagine-bundle": "*",
        "simplethings/form-extra-bundle": "dev-master",
        "antimattr/google-bundle": "dev-master",
        "doctrine/doctrine-fixtures-bundle": "dev-master",
        "genemu/form-bundle": "2.1.*",
        "behat/behat":                  "2.4.*@stable",
        "behat/mink":                   "1.4.*@stable",
        "behat/symfony2-extension":     "*@stable",
        "behat/mink-extension":         "*@stable",
        "behat/mink-selenium2-driver":  "*@stable",
        "behat/mink-browserkit-driver":  "*",
        "liip/functional-test-bundle": "dev-master"
    },
    "scripts": {
        "post-install-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "minimum-stability": "dev",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web"
    },
    "config": {
        "bin-dir": "bin/"
    }
}

Answers:


535

您可以运行composer show -i(的缩写--installed)。

在最新版本中,只需使用即可composer show

-i选项已被弃用。

您还可以使用globalcomposer 的安装方式:composer global show


写这篇文章的人试图让这个使用composer.phar和PHP
Yashrajsinh Jadeja

9
现在不建议使用-i选项。composer show列出默认情况下已安装的软件包。
herve

可能不用说会composer show --help打印所有可用选项。
Gerard Roche

52

列出全局安装的作曲家程序包:

composer global show -i


12

该命令的行为已被修改,因此您不必传递该-i选项:

[10:19:05] coil@coil:~/workspace/api$ composer show -i
You are using the deprecated option "installed". 
Only installed packages are shown by default now. 
The --all option can be used to show all packages.

10

如果您只想检查一个版本,则可以

composer show -- twig/twig

请注意,默认情况下现在仅显示已安装的软件包,并且已弃用已安装的选项。


6

上面伊万的答案很好:

composer global show -i

添加的信息:如果您收到类似以下的消息:

Composer could not find a composer.json file in ~/.composer

...您可能尚未安装任何软件包。如果是这样,则可以忽略包含以下内容的消息的下一部分:

... please create a composer.json file ...

...一旦您安装了软件包,该消息就会消失。


2

如果要安装Symfony2.2,可以composer.json 在Symfony博客上看到完整的更改。

只需根据此更新文件,然后运行即可composer update。这将在项目上安装所有新的依赖项和Symfony2.2。


如果您不想更新到Symfony2.2,但遇到依赖项错误,则应该发布这些错误,以便我们进一步为您提供帮助。


原来我遇到的问题是FOS用户捆绑包2x与奏鸣曲用户捆绑包之间的不兼容性所致
Dan

1
@丹,我认为这是因为SonataUserBundle的配置方式不正确。那是昨天确定的。
Wouter J

0

有没有一种方法可以通过$ event-> getComposer()-> getRepositoryManager()-> getAllPackages()来获取它

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.