Composer global 需要 Laravel/Installer 不适用于 Ubuntu

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37171316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:46:41  来源:igfitidea点击:

Composer global require Laravel/Installer not working on Ubuntu

phplinuxlaravelubuntucomposer-php

提问by JonnySerra

I'm trying to run composer global require "laravel/installer"on my Ubuntu machine (Trenta OS Distro) and for some reason I can't get it to install.

我正在尝试composer global require "laravel/installer"在我的 Ubuntu 机器(Trenta OS Distro)上运行,但由于某种原因我无法安装它。

file_put_contents(./composer.json): failed to open stream: Permission denied

file_put_contents(./composer.json):无法打开流:权限被拒绝

I get the error above on every attempt. I've been unable to find any help on google so I'm guessing this isn't a very common problem. I tried whereiscommand on that file and it gives me a location

每次尝试时我都会收到上述错误。我一直无法在谷歌上找到任何帮助,所以我猜这不是一个很常见的问题。我whereis在那个文件上试过 命令,它给了我一个位置

/usr/local/bin/composer

I tried running chmod -R 777on that file but it did nothing. I don't know what else to do.

我尝试chmod -R 777在该文件上运行但它什么也没做。我不知道还能做什么。

Composer was installed on my machine with the following command

使用以下命令在我的机器上安装了 Composer

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

I thought composer.jsononly comes with projects, but I shouldn't need an existing project in order to simply set up the Laravel Installer right?

我以为composer.json只附带项目,但我不应该需要一个现有的项目来简单地设置 Laravel 安装程序,对吗?

回答by David Nore?a

I had the same problem and after reading this answerI solved it updating the .composerfolder permissions:

我遇到了同样的问题,在阅读此答案后,我解决了更新.composer文件夹权限的问题:

sudo chown -R $USER:$USER /home/$USER/.composer

Where $USERis your machine's username.

$USER你机器的用户名在哪里。

Update: As @Lucas Bustamante pointed, you don't need to change $USER for your username, its an environment variable already.

更新:正如@Lucas Bustamante 所指出的,您不需要为您的用户名更改 $USER,它已经是一个环境变量。

As Ian Warnercommented out, is not a good idea to run composer as sudo user, because it can lead to security issues.

正如Ian Warner评论的那样,以 sudo 用户身份运行 composer 不是一个好主意,因为它会导致安全问题。

回答by Arvin Ismaili

I think this may solve your problem as it did for me.

我认为这可能会像对我一样解决您的问题。

I made a bash file for the whole process of global installation of Laravel. download it from here, open a terminal in the bash file directory and run the command below:

我为Laravel全局安装的整个过程制作了一个bash文件。 从这里下载它,在bash 文件目录中打开一个终端并运行以下命令:

bash Laravel_Global_Installer.sh

This bash file manages installations of:

这个 bash 文件管理安装:

  1. Latest version of PHP and its extensions
  2. Latest version of Composer (Global)
  3. Latest version of Laravel (Global)
  1. 最新版本的 PHP 及其扩展
  2. Composer 最新版本(全球)
  3. Laravel 最新版本(全球)

This will help you install Composer Globally and without sudo. Therefore you will be able to install Laravel Globally.

这将帮助您在没有 sudo 的情况下全局安装 Composer。因此,您将能够全局安装 Laravel。

回答by FoneBay

usr/local/bin/composer composer global require "laravel/installer"

usr/local/bin/composer composer create-project --prefer-dist laravel/laravel myblog

回答by Nitin

use sudo before the command,

在命令前使用 sudo,

for e.g.: sudo composer global require "laravel/installer"

例如:sudo composer global 需要“laravel/installer”