87

I am trying to set up Laravels Valet (Valet is a Laravel development environment for Mac). Everything works until it comes to the command "valet install". This command must be executed in terminal. But I got the error "command not found". Any ideas, why? Do I have to update my PATH or something else?

I switched to OS X a few days ago. Before that, I was a windows user. So I am a total newbie.

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
Brotzka
  • 2,959
  • 4
  • 35
  • 56
  • Possible duplicate of [Laravel installation: How to place the ~/.composer/vendor/bin directory in your PATH?](https://stackoverflow.com/questions/25373188/laravel-installation-how-to-place-the-composer-vendor-bin-directory-in-your) – MrTux Feb 12 '18 at 15:10

20 Answers20

281

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
Mohamed Said
  • 4,413
  • 6
  • 35
  • 52
69

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).

rjb
  • 9,036
  • 2
  • 44
  • 49
  • This test flow worked for me, I had just forgotten to restart the terminal – Björn Hjorth Jan 30 '19 at 11:31
  • The first steps seem to work, but when I try `source ~/.bash_profile`, I get `~/.bash_profile No such file or directory`, then weather or not I close and open a new terminal window, I still get `-bash: valet: command not found`. – BBaysinger Mar 06 '19 at 00:14
  • 1
    This answer mentions paths including `~/.composer`, but I needed to change them to `~/.config/composer`, as other answers on this page mentioned. – Ryan Jul 19 '21 at 19:42
  • Had to update my path to /.config/composer too. Otherwise this works great. – Second2None Mar 02 '22 at 23:59
  • This flow worked perfectly for me using a M1 Mac, thank you! – DevSem Sep 04 '22 at 02:07
37

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

Nicu Criste
  • 3,072
  • 1
  • 19
  • 9
22

you just have to use:

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

then

valet install

ready :)

JAlvaroJS
  • 229
  • 2
  • 3
  • Thank you so much, this worked for me.. My path before was pointing to '/opt/homebrew/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin' – Lukas Apr 01 '23 at 16:30
16

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
Z.Lin
  • 28,055
  • 6
  • 54
  • 94
Martins Gathu
  • 161
  • 1
  • 3
15

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
Moritz
  • 249
  • 2
  • 11
12

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
Muhaimin Taib
  • 306
  • 2
  • 4
8

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

Md Mazedul Islam Khan
  • 5,318
  • 4
  • 40
  • 66
6

This command might solve your problem

test -d ~/.composer && bash ~/.composer/vendor/bin/valet install || bash ~/.config/composer/vendor/bin/valet install
VipinKundal
  • 442
  • 6
  • 14
4

In Ubuntu 18.04 do this:

echo "export PATH=$PATH:$HOME/.config/composer/vendor/bin" >> ~/.bashrc
source ~/.bashrc
Kornel
  • 4,184
  • 4
  • 28
  • 30
2

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.

Mete Kabak
  • 332
  • 3
  • 19
2

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
Bedram Tamang
  • 3,748
  • 31
  • 27
1

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

1

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

1

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

reylimjr
  • 361
  • 8
  • 16
0

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

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

in

/etc/profile

then

source ~/etc/profile

Viraj Singh
  • 1,951
  • 1
  • 17
  • 27
0

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
Md Omar Faruk
  • 303
  • 3
  • 10
0

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.

Sinan Eldem
  • 5,564
  • 3
  • 36
  • 37
0

iTerm Terminal Users / ohmyzsh

Step 1. vi ~/.zshrc

Step 2. mention below line anywhere

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

Save, Exit & Open a new Terminal. That's it ✌️

Now type valet -v

Ranjan Fadia
  • 1,363
  • 1
  • 14
  • 18
0

I think you just nid composer remove and install again next step you can download and install valet