The command could not be located because '/snap/bin' is not included in the PATH environment variable
Asked Answered
C

6

44

when i try to run git-all-secrets i got Dockerfile: command not found and this is the command include correct information

here is an example of the issue

root@momo22:/home/momo/git-all-secrets# docker run -it abhartiya/tools_gitallsecrets -token=9a8b60a10cf683f238e05 -org=bugcrwod
Command 'docker' is available in '/snap/bin/docker'
The command could not be located because '/snap/bin' is not included in the PATH environment variable.
docker: command not found
root@momo22:/home/momo/git-all-secrets# 
Cassius answered 20/7, 2019 at 4:53 Comment(3)
what os? and what are the results of: "whereis docker"?Fieldsman
I have the same error when running docker on ubuntu 18.04 . I have chosen the docker to be installed during the installation of the serverDwaynedweck
I can confirm that even on Ubuntu 20.04 the case is consistent with the user above, docker gets installed into /snap/bin and not added to $PATH, see answers below on how to do it.Toadfish
L
91

Temporary solution:

Run the command export PATH=$PATH:/snap/bin

Permanent solution:

Edit /etc/environment and add /snap/bin in the list then restart your system.

Links

answer for similar error with same fix
More info on /etc/enviroment

Leahy answered 9/8, 2019 at 17:29 Comment(3)
No need to restart the system. Just use source /etc/environmentNursery
This /snap/bin already in /etc/environment list, I am trying to open project which stored on my external harddisk. If i open new terminal, and changing path to the directory, code . command working fineRetroflex
Strange this has so many upvotes, as written this is incomplete and doesn't work especially if the environment file is empty. See Jay Harry's solution.Concertino
C
26

you can add the path into .bashrc file

$ echo 'export PATH=$PATH:/snap/bin' >> ~/.bashrc

open new terminal or execute this command

$ source ~/.bashrc

Christly answered 25/4, 2020 at 5:23 Comment(1)
This solution only applies for Bash users. Other shells like Zsh require a similar, but different, approach.Geryon
J
20

To fix this issue do the following:

  1. Open the file /etc/environment.
  2. Add /snap/bin to the end of the PATH Variable and concatenate using the : character.

    Example lets assume we had the PATH variable in the file was: Path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"

    After your update this will look like: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/snap/bin

  3. Finally to update your shell and have the PATH variable ready to use, run source /etc/environment
  4. Done
June answered 18/4, 2020 at 17:57 Comment(1)
This is the best and most complete answer - thank you!Concertino
G
1

If you come here and are just on Ubuntu rather than docker and you have just installed snapd without logging out/in again, log out then in again - you don't need to modify any files.

Gonzales answered 27/10, 2020 at 5:47 Comment(0)
E
0
  1. Open the ~/.bashrc with nano or vim => vim ~/.bashrc
  2. add export PATH=$PATH:/snap/bin at the end of the file
  3. log out from your user and log in again or reboot

if ~/.bashrc doesn't exist:

  1. create ~/.bashrc file and open it => touch ~/.bashrc && vim ~/.bashrc
  2. add PATH=$PATH:/snap/bin
  3. logout from your user and login again or reboot

if you don't want to logout or reboot run these commands:

  1. sudo su ${USER}
  2. bash
Evangelist answered 3/2, 2021 at 6:40 Comment(0)
U
0
  • open ~/.bash_profile
  • add export PATH=$PATH:/snap/bin and save the changes
  • run source ~/.bash_profile

you can open ~/.bash_profile with vi or gedit

Unesco answered 24/10, 2022 at 22:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.