PHP 全局安装包:apt-get vs composer [英] PHP install package globally: apt-get vs composer
问题描述
我发现有两个选项可以在 Linux (Ubuntu 16.04) 中全局安装 PHP 包:
I found there are two options to install PHP package globally in Linux (Ubuntu 16.04):
使用
composer
:
composer global require symfony/finder
包将位于 ~/.config/composer/vendor/
使用apt-get
:
apt-get install php-symfony-finder
该包将位于 /usr/share/php/
这个目录 /usr/share/php/
也在默认 PHPs include_path
(我有 PHP 7.2)
This directory /usr/share/php/
is also in default PHPs include_path
(I have PHP 7.2)
<小时>
我有几个问题:
There are several questions I have:
为什么要全局安装包?
我知道全局安装 php 工具很有用,比如 phpunit
- 它有二进制文件,它允许你在任何地方运行测试,所以你不必在每个项目中安装它.但是例如 symfony/finder
呢?全局安装的这个包有什么特殊用途?
I know it's useful to install php tools globally, like phpunit
- It has binary file and it allows you to run tests everywhere, so you don't have to install it in every project.
But what about symfony/finder
for example ? What is particular use of this package installed globally ?
1 和 2 选项有什么区别?
它有什么不同的用例或不同的效果吗?
Does it have any different use cases or different effects ?
推荐答案
为什么我要全局安装包?
通常,这些是您几乎想要在每个项目中使用的依赖项,因为它们在系统级别可用,您可以使用它们而无需在您创建的每个应用程序中复制它们的依赖项.
Normally, these are dependencies you want to use in almost every project, because they are available at a system level you can use them without duplicating their dependencies in every application you create.
例如,在我的例子中,我有 php_md
,php_cs
用于代码格式化,phpunit
用于测试.
For example, in my case I have php_md
, php_cs
for code formatting, phpunit
for testing.
1 和 2 选项有什么区别?
两者都是包管理器,它们确保安装的每个包都有正确的依赖项,因此它们的核心功能是相似的.
Both are package managers, they make sure every package installed has the correct dependencies, so their core functionality is similar.
现在,它们有几个区别:
Now, they have several differences:
- 他们专注于他们管理的包,
composer
专用于基于php
的包,但apt-get
用于 Linux 和更多系统级别面向. - 他们的包数据库,
composer
使用 packagist 和apt-get
使用精选的存储库和 ppa(您可以在/var/lib/apt/lists/
中找到它们). - 软件包选择,因为
composer
专门研究php
,您可以期待与php
相关的更多种类.
- Their focus in the packages they manage,
composer
is specific forphp
based packages butapt-get
is for Linux and more system level oriented. - Their package database,
composer
uses packagist andapt-get
uses a selection of repositories and ppas (you can find them in/var/lib/apt/lists/
). - The package selection, since
composer
is specialized inphp
you can expect a wider variety in anythingphp
related.
总而言之,您显然可以同时使用两者,但我建议您将所有 php
与 composer 相关,将它们统一在同一个管理器下.
In conclusion, you can clearly make it work with both, but I would recommend you to keep everything php
related on composer, unifying them under the same manager.
欢迎任何我忽略的其他差异或更正.
Any other difference or correction I've overlooked is welcome.
这篇关于PHP 全局安装包:apt-get vs composer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!