无法打开输入文件:/usr/local/bin/composer.phar



如果你能相信的话,在安装作曲家时遇到问题。

iOS Sierra (10.12.6)

这是我的代码

Samers-MBP:~ samer$ php composer-setup.php
All settings correct for using Composer
Downloading...
php -r "unlink('composer-setup.php');"
Composer (version 1.5.2) successfully installed to: 
/Users/samer/composer.phar
Use it: php composer.phar
Samers-MBP:~ samer$ php -r "unlink('composer-setup.php');"
Samers-MBP:~ samer$ sudo mv /Users/samer/composer.phar 
/usr/local/bin/composer
Password:
Samers-MBP:~ samer$ composer
Could not open input file: /usr/local/bin/composer.phar
Samers-MBP:~ samer$ cd /usr/local/bin
Samers-MBP:bin samer$ composer
Could not open input file: /usr/local/bin/composer.phar
Samers-MBP:bin samer$ 

我只能使用 SUDO 运行作曲家

Samers-MBP:~ samer$ sudo composer info
Password:
Do not run Composer as root/super user! See 
https://getcomposer.org/root for details
nesbot/carbon             1.22.1  A simple API extension for DateTime.
symfony/polyfill-mbstring v1.6.0  Symfony polyfill for the Mbstring 
extension
symfony/translation       v3.3.10 Symfony Translation Component
Samers-MBP:~ samer$ 

安装了 Laravel,但我无法访问$HOME/.bashrc(访问被拒绝)或~/.bash_profile将作曲家的系统范围的供应商 bin 目录放在我的$PATH中......

我不知道我做错了什么,或者为什么它不起作用。

运行

典型的安装说明后,我在MacOS Catalina上遇到了类似的问题:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '795f976fe0ebd8b75f26a6dd68f78fd3453ce79f32ecb33e7fd087d39bfeb978342fb73ac986cd4f54edd0dc902601dc') { echo 'Installer verified'; } else { echo 'Installer corrupt';         
unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

我怀疑它需要执行权限。初始权限为:

-rwxr-xr-x   1 username  staff   1994202 Sep 25 08:39 composer

虽然它对我有执行权限,但我更改了它以/usr/local/bin制作其他所有内容:

-rwxr-xr-x   1 root  wheel   1994202 Sep 25 08:39 composer

我仍然有这个错误:

Could not open input file: /usr/local/bin/composer.phar

我仔细检查了我的 PATH 变量:

% echo $PATH
/usr/local/bin:/usr/local/php5/bin:...

我找到了我的bash_profile文件,忘记了我在zsh上,所以我为我的zshrc文件提供了资源。

% source ~/.bash_profile
% source ~/.zshrc

还是没有骰子。最终我把文件名改成了composer.phar

% sudo mv /usr/local/bin/composer /usr/local/bin/composer.phar

然后它工作了

% composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ / __ `__ / __ / __ / ___/ _ / ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
____/____/_/ /_/ /_/ .___/____/____/___/_/
                /_/
Composer version 1.10.13 2020-09-09 11:46:34
...

这在过去对我来说从来都不是必需的,但目前它正在发挥作用。

在终端上使用以下命令更改文件名

sudo mv /usr/local/bin/composer /usr/local/bin/composer.phar

然后输入"作曲家"

   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ / __ `__ / __ / __ / ___/ _ / ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
____/____/_/ /_/ /_/ .___/____/____/___/_/
                    /_/
Composer version 2.3.10 2022-07-13 15:48:23
Usage:
  command [options] [arguments]
Options:
  -h, --help                     Display help for the given command. When no command is given display help for the list command
  -q, --quiet                    Do not output any message
  -V, --version                  Display this application version
      --ansi|--no-ansi           Force (or disable --no-ansi) ANSI output
  -n, --no-interaction           Do not ask any interactive question
      --profile                  Display timing and memory usage information
      --no-plugins               Whether to disable plugins.
      --no-scripts               Skips the execution of all scripts defined in composer.json file.
  -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
      --no-cache                 Prevent use of the cache
  -v|vv|vvv, --verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
  about                Shows a short information about Composer.
  archive              Creates an archive of this composer package.
  browse               [home] Opens the package's repository URL or homepage in your browser.
  check-platform-reqs  Check that platform requirements are satisfied.
  clear-cache          [clearcache|cc] Clears composer's internal package cache.
  completion           Dump the shell completion script
  config               Sets config options.
  create-project       Creates new project from a package into given directory.
  depends              [why] Shows which packages cause the given package to be installed.
  diagnose             Diagnoses the system to identify common errors.
  dump-autoload        [dumpautoload] Dumps the autoloader.
  exec                 Executes a vendored binary/script.
  fund                 Discover how to help fund the maintenance of your dependencies.
  global               Allows running commands in the global composer dir ($COMPOSER_HOME).
  help                 Display help for a command
  init                 Creates a basic composer.json file in current directory.
  install              [i] Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
  licenses             Shows information about licenses of dependencies.
  list                 List commands
  outdated             Shows a list of installed packages that have updates available, including their latest version.
  prohibits            [why-not] Shows which packages prevent the given package from being installed.
  reinstall            Uninstalls and reinstalls the given package names
  remove               Removes a package from the require or require-dev.
  require              Adds required packages to your composer.json and installs them.
  run-script           [run] Runs the scripts defined in composer.json.
  search               Searches for packages.
  self-update          [selfupdate] Updates composer.phar to the latest version.
  show                 [info] Shows information about packages.
  status               Shows a list of locally modified packages.
  suggests             Shows package suggestions.
  update               [u|upgrade] Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
  validate             Validates a composer.json and composer.lock.

您必须授予它执行权限:

试试这个:

sudo chmod +x /usr/local/bin/composer

然后

composer -v

只需执行以下步骤即可安装作曲家。在 Mac 上使用作曲家不会有任何问题:

sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
sudo php -r "unlink('composer-setup.php');"
sudo chmod +x /usr/local/bin/composer

相关内容

  • 没有找到相关文章

最新更新