63

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
  • 17,710
  • 5
  • 27
  • 70
Brotzka
  • 2,451
  • 2
  • 29
  • 48
  • 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

18 Answers18

217

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
  • 3,705
  • 6
  • 32
  • 51
  • 10
    This is the answer I keep finding, EVERYWHERE! Yet it does not solve my problem.. valet is still `command not found`. Is there something else that might be overlooked for some inexperienced developers? – nclsvh Mar 07 '17 at 12:46
  • 16
    Maybe ur using zsh? If so add ~/.composer/vendor/bin to export PATH in ~/.zshrc – halfred Mar 16 '17 at 21:36
  • 2
    and if its still not working then u need to close and reopen the terminal. – hatemjapo Feb 01 '19 at 12:24
  • 6
    For me using ubuntu18.04, this path is a bit different though. It's `~/.config/composer/vendor/bin/` for some reason. – Fred Lai Jul 17 '19 at 04:10
  • Worked for me on High Sierra. – ItsJoeTurner Aug 24 '19 at 08:01
  • 2
    I modified the .bash_profile file directly using nano ~./bash_profile, added `export PATH="$PATH:$HOME/.composer/vendor/bin"` at end of file, saved, restarted terminal and it worked (I'm on Big Sur) – Kyle Yeo Dec 09 '20 at 04:19
  • this is very helpful for m1 mac user like me – dczii May 21 '21 at 03:17
  • Thank you. This worked for me. I was stuck at "command not found" after typing valet install – JAL Jun 19 '21 at 20:46
51

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
  • 8,718
  • 2
  • 42
  • 48
  • 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
31

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
  • 2,462
  • 1
  • 18
  • 9
13

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
  • 25,090
  • 5
  • 44
  • 85
Martins Gathu
  • 131
  • 1
  • 3
9

you just have to use:

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

then

valet install

ready :)

JAlvaroJS
  • 91
  • 1
  • 1
6

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
  • 4,096
  • 3
  • 38
  • 61
6

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
  • 131
  • 1
  • 6
4

In Ubuntu 18.04 do this:

echo "export PATH=$PATH:$HOME/.config/composer/vendor/bin" >> ~/.bashrc
source ~/.bashrc
Kornel
  • 3,883
  • 4
  • 25
  • 30
3

This command might solve your problem

test -d ~/.composer && bash ~/.composer/vendor/bin/valet install || bash ~/.config/composer/vendor/bin/valet install
VipinKundal
  • 402
  • 5
  • 14
3

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
  • this is right in case for .zshrc also the location might be different like $HOME/.config/composer/vendor/bin – Min Somai Feb 28 '22 at 09:31
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
  • 292
  • 3
  • 18
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
  • 2,797
  • 24
  • 20
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

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,060
  • 12
  • 23
0

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
  • 341
  • 6
  • 14
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
  • 133
  • 2
  • 8
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,110
  • 3
  • 33
  • 36