laravel 如何将 ~/.composer/vendor/bin 目录放在 PATH 中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25373188/
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-08 16:42:06  来源:igfitidea点击:

How to place the ~/.composer/vendor/bin directory in your PATH?

bashlaravelpath

提问by which1ispink

I'm on Ubuntu 14.04 and I've been trying all possible methods to install Laravel to no avail. Error messages everything I try. I'm now trying the first method in the quickstart documentation, that is, via Laravel Installer, but it says to "Make sure to place the ~/.composer/vendor/bindirectory in your PATHso the Laravel executable is found when you run the Laravel command in your terminal." so my question is, how do I do that? This may be a simple question but I'm really frustrated and would appreciate any help.

我在 Ubuntu 14.04 上,我一直在尝试所有可能的方法来安装 Laravel,但无济于事。错误消息我尝试的一切。我现在正在尝试快速入门文档中的第一种方法,即通过 Laravel 安装程序,但它说“确保将~/.composer/vendor/bin目录放在您的目录中,PATH以便在终端中运行 Laravel 命令时找到 Laravel 可执行文件。” 所以我的问题是,我该怎么做?这可能是一个简单的问题,但我真的很沮丧,希望得到任何帮助。

回答by MrTux

To put this folder on the PATH environment variable type

将此文件夹放在 PATH 环境变量类型上

export PATH="$PATH:$HOME/.composer/vendor/bin"

This appends the folder to your existing PATH, however, it is only active for your current terminal session.

这会将文件夹附加到您现有的 PATH,但是,它仅对您当前的终端会话有效。

If you want it to be automatically set, it depends on the shell you are using. For bash, you can append this line to $HOME/.bashrcusing your favorite editor or type the following on the shell

如果您希望它自动设置,则取决于您使用的外壳。对于 bash,您可以将此行附加到$HOME/.bashrc使用您喜欢的编辑器或在 shell 上键入以下内容

echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc

In order to check if it worked, logout and login again or execute

为了检查它是否有效,注销并再次登录或执行

source ~/.bashrc

on the shell.

在外壳上。

PS: For other systems where there is no ~/.bashrc, you can also put this into ~/.bash_profile

PS:对于其他没有的系统,也~/.bashrc可以把这个放到~/.bash_profile

PSS: For more recent laravel you need to put $HOME/.config/composer/vendor/binon the PATH.

PSS:对于最近的laravel你需要把$HOME/.config/composer/vendor/binPATH

PSSS: If you want to put this folder on the path also for other shells or on the GUI, you should append the said exportcommand to ~/.profile(cf. https://help.ubuntu.com/community/EnvironmentVariables).

PSSS:如果您想将此文件夹也放在其他 shell 或 GUI 的路径上,您应该将上述export命令附加到~/.profile(参见https://help.ubuntu.com/community/EnvironmentVariables)。

回答by Alexander Kim

Detailed instructions:

详细说明:

in your ~/.bashrc add these lines:

在您的 ~/.bashrc 中添加以下几行:

export PATH="$PATH:~/.composer/vendor/bin"

Then reload:

然后重新加载:

source ~/.bashrc

Check if its added correctly:

检查它是否正确添加:

echo $PATH

/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/web/bin:~/.composer/vendor/bin

回答by Vagner Leitte

In Ubuntu 16.04 LTS with composer globally installed, this worked for me.

在全局安装了 Composer 的 Ubuntu 16.04 LTS 中,这对我有用。

Edit the .bashrc file in your home directory puting the path to the composer bin folder that is located in /your/home/.config/composer/vendor/bin

编辑主目录中的 .bashrc 文件,将路径放在位于 /your/home/.config/composer/vendor/bin 中的 composer bin 文件夹

echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc

source ~/.bashrc

If not works, verify the path to the composer bin directory and close and reopen the terminal. Otherwise, try to logoff and login in the Ubuntu.

如果不起作用,请验证 composer bin 目录的路径并关闭并重新打开终端。否则,尝试在 Ubuntu 中注销并登录。

Also works in ubuntu 18.04. Thanks @chifliiiii for your feedback.

也适用于 ubuntu 18.04。感谢@chifliiiii 的反馈。

回答by Forca001

For setting the PATH on Yosemite (OS X 10.10.5), use the command below:

要在 Yosemite (OS X 10.10.5) 上设置 PATH,请使用以下命令:

echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bash_profile

To reload either quit terminal and start up again or use:

要重新加载退出终端并重新启动或使用:

source ~/.bash_profile

Helped me, hope it helps someone else out there!

帮助了我,希望它可以帮助其他人!

回答by grit45

I did all of the above and it didn't work for me.

我做了以上所有的事情,但它对我不起作用。

I just copied this into my terminal and it worked for me.

我只是将其复制到我的终端中,它对我有用。

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

回答by akbarbin

This is for setting PATH on Mac OS X Version 10.9.5.

这是用于在 Mac OS X 版本 10.9.5 上设置 PATH。

I have tried to add $HOME because I use user profile :

我尝试添加 $HOME 因为我使用用户配置文件:

echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc

When you do not use user profile:

当您不使用用户配置文件时:

echo 'export PATH="$PATH:~/.composer/vendor/bin"' >> ~/.bashrc

Then reload:

然后重新加载:

source ~/.bashrc

I hope this help you.

我希望这对你有帮助。

回答by Darren Murphy

Open the Mac Terminal:

打开 Mac 终端:

vi ~/.bashrc

If you haven't used vi, it may look a little funny at first, so enter the following code carefully, in order:

如果你没用过vi,一开始可能会觉得有点好笑,所以仔细输入以下代码,按顺序:

i
export PATH="$PATH:$HOME/.composer/vendor/bin"

PRESS ESC

按ESC

:
w

PRESS ENTER

按回车键

:
q

PRESS ENTER

按回车键

Now you should have returned to the normal terminal view.

现在您应该已经返回到正常的终端视图。

Check that composer now has the correct path:

检查 Composer 现在有正确的路径:

cd ~/.composer
echo $PATH

If you see the path including your file directory, (e.g. /Users/JeffStrongman/.composer/vendor/bin), you're good to go.

如果您看到包含您的文件目录的路径(例如 /Users/JeffStrongman/.composer/vendor/bin),您就可以开始了。

cd

Then run your installation. I ran into this problem, while configuring my Mac to use Laravel Valet.

然后运行您的安装。我在配置 Mac 以使用 Laravel Valet 时遇到了这个问题。

Example (optional)

示例(可选)

valet install

回答by Martijn van der Bruggen

For Linux Mint 18: edit ~/.bashrc and add this line to it at the bottom:

对于 Linux Mint 18:编辑 ~/.bashrc 并在底部添加以下行:

export PATH="$PATH:$HOME/.config/composer/vendor/bin"

then resource .bashrc (type in console):

然后资源 .bashrc (在控制台中输入):

source ~/.bashrc (or close and reopen the terminal)

test it by typing in the console:

通过在控制台中键入来测试它:

echo $PATH

or type in console:

或在控制台输入:

laravel

回答by Jignesh Joisar

add environment variable into bashrcfile

将环境变量添加到 bashrc文件中

For Ubuntu 17.04 and 17.10:

对于 Ubuntu 17.04 和 17.10:

echo 'export PATH="~/.config/composer/vendor/bin"' >> ~/.bashrc

For Ubuntu 18.04

对于 Ubuntu 18.04

echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc

to Check environment variable working or not first reload the bashrcfile

检查环境变量是否工作首先重新加载bashrc文件

source ~/.bashrc

if not working any method then First Check Where is install Composerto Check Run This Command :

如果没有任何方法,则首先检查安装 Composer 的位置以检查运行此命令:

locate composer -l 1

then Copy Output add output into this line and run again command.

然后复制输出将输出添加到这一行并再次运行命令。

 echo 'export PATH="OUTPUTHERE/vendor/bin"' >> ~/.bashrc

After Successfully Laravel Command Work Give a Permission To Parent Folder (for example u are using apache server than give permission to apache web listing directory like that)

成功 Laravel 命令工作后,授予父文件夹的权限(例如,您使用的是 apache 服务器,而不是授予 apache web 列表目录的权限)

sudo chown $USER:$USER -R /var/www/html/

回答by Yoseph

Adding export PATH="$PATH:~/.composer/vendor/bin" to ~/.bashrcworks in your case because you only need it when you run the terminal.
For the sake of completeness, appending it to PATH in /etc/environment (sudo gedit /etc/environmentand adding ~/.composer/vendor/binin PATH)will also work even if it is called by other programs because it is system-wide environment variable.
https://help.ubuntu.com/community/EnvironmentVariables

export PATH="$PATH:~/.composer/vendor/bin" 添加到 ~/.bashrc对您有效,因为您只在运行终端时需要它。
为了完整起见,将其附加到 /etc/environment 中的 PATH (sudo gedit /etc/environment并在 PATH 中添加~/.composer/vendor/bin即使它被其他程序调用也将起作用,因为它是系统- 范围的环境变量。
https://help.ubuntu.com/community/EnvironmentVariables