找不到 Laravel“代客安装”

我试图建立 Laravels 代客泊车(Valet 是 Mac 的 Laravel 开发环境)。一切工作,直到它来到命令“代客安装”。此命令必须在终端中执行。但是我得到错误“命令未找到”。知道为什么吗?我必须更新我的 PATH 或其他东西吗?

几天前我换成了 OS X。在那之前,我是 Windows 用户。所以我完全是个新手。

99246 次浏览

Yes, you need to make sure that ~/.composer/vendor/bin directory is in your system's PATH, you can check this by running:

echo $PATH

If you can't see it there, then you need to add this to your ~/.bash_profile:

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

Add ~/.composer/vendor/bin directory to your PATH variable.

If you have a fresh installation, you may not have the PATH variable contains your home path. So, adding the $HOME variable would require like the following:

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

with new composer installation, you need to add a new path which is

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

Then you need to

chown YOUR_USERNAME ~/.config

for accessing composer packages without sudo command.

If you're getting the error message "valet: command not found", it's likely that PHP's Composer is not in your PATH variable, for instance:

$ valet install
-bash: valet: command not found

You can confirm if Laravel Valet was successfully installed by running the following command:

ls -al ~/.composer/vendor/bin/valet

If successfull, you'll see the symlink for Valet in Composer's bin directory pointing to Laravel in the vendor directory:

~/.composer/vendor/bin/valet@ -> ../laravel/valet/valet

To test whether your PATH is missing Composer, try running the Valet command directly:

~/.composer/vendor/bin/valet --version

If you're shown the Laravel version number, (e.g. Laravel Valet 2.0.4), this indicates Valet is installed but you need to update your PATH variable to include Composer for the valet command to work globally.

In your Terminal, execute the following command which will append Composer to your shell's PATH:

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

For the changes to take effect, you'll need to exit and re-open your Terminal window or tab.

Alternatively, you can simply source your shell's profile, which doesn't require quitting your active session:

source ~/.bash_profile

If you have a different shell environment or you're using a shell other than Bash, you will need to source its configuration profile instead (e.g. .bashrc, .zshrc, config.fish).

Make sure that ~/.composer/vendor/bin directory is in your system's PATH, you can check this by running:

echo $PATH

If not there, open your ~/.bash_profile and add this code:

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

Then run:

composer global require laravel/valet --dev

Once it is done, run:

valet install

This command might solve your problem

test -d ~/.composer && bash ~/.composer/vendor/bin/valet install || bash ~/.config/composer/vendor/bin/valet install

I'm using oh-my-zsh so:

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

You may replace .zshrc with .bashrc

In Ubuntu 18.04 do this:

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

I have installed Composer version 2 and found that composer default path is ~/.config/composer/ and similarly valet is also installed on /.config/composer/vendor/bin/valet. So to solve this issues I added the composer path to ~/.bashrc file as:

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

In my case I've to update /etc/profile file added

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

in

/etc/profile

then

source ~/etc/profile

If valet install doesn’t work, but ~/.composer/vendor/bin/valet --version does work, try installing it via

~/.composer/vendor/bin/valet install

To See if that worked, check

valet --version

you just have to use:

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

then

valet install

ready :)

For me worked

write in console

  1. cd ~/.composer/vendor/bin
  2. pwd
  3. copy pwd command result
  4. export PATH=$PATH: (pwd command result)
  5. valet install

I think I explained well

I found a fix on this website, and it fixed my issue.

test -d ~/.composer && bash ~/.composer/vendor/bin/valet install || bash ~/.config/composer/vendor/bin/valet install

https://hidayatabisena.medium.com/solving-issues-command-not-found-laravel-valet-install-on-macos-mojave-2a7629759a9f

In my case I found the valet location by manual search

enter image description here

Then add the the valet file path to PATH variable

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

Then I ran the install command and it worked

valet install

Php may be not installed

Use your prefered version with:

brew install php
// or
brew install php@8.0
// or
brew install php@7.4

This solved my issue.

If you're using zsh, you cannot use ~ as path to home dir, use $HOME instead.

In .zshrc file, instead of adding this:

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

Add this and the path will resolve:

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