临时设置:在命令前添加环境变量,如 Linux/macOS 下使用 COMPOSER_MEMORY_LIMIT=-1 composer install;2. 永久设置:Linux/macOS 在 ~/.bashrc 等文件中添加 export COMPOSER_MEMORY_LIMIT=-1,Windows 在系统环境变量中添加变量名 COMPOSER_MEMORY_LIMIT 和值 -1;3. 可用值包括 -1(无限制)、512M、2G 等,但不能超过 php.ini 中 memory_limit 的设定。

要设置 Composer 的内存限制环境变量 COMPOSER_MEMORY_LIMIT,你可以通过在运行 Composer 命令前临时设置,或在系统/用户环境中永久设置。
Windows(CMD):
set COMPOSER_MEMORY_LIMIT=-1 && composer installWindows(PowerShell):
$env:COMPOSER_MEMORY_LIMIT="-1"; composer installLinux / macOS:
COMPOSER_MEMORY_LIMIT=-1 composer install 这种方式只对当前命令生效,适合临时解决内存不足问题。Linux / macOS:
编辑 shell 配置文件(如 ~/.bashrc、~/.zshrc 或 ~/.profile),添加: export COMPOSER_MEMORY_LIMIT=-1 保存后运行 source ~/.bashrc(或对应文件)使其生效。Windows:
打开“系统属性” → “高级” → “环境变量”,在用户或系统变量中添加:Composer 默认使用 PHP 的 memory_limit,设置 COMPOSER_MEMORY_LIMIT 可覆盖该限制。遇到 "Allowed memory size exhausted" 错误时,优先考虑此变量。
基本上就这些。以上就是composer 环境变量 COMPOSER_MEMORY_LIMIT 如何设置?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号