How do I un-corrupt a command reference in bash?

On a CentOS 7 server, I am installing Docker and Docker Machine. The installation has required some manual re-setting of BIOS options and then rebooting the operating system during the installation process. At first, the docker-machine command was found by bash. But it seems that some of bash's references have been broken during the reboots. As a result, the commands below for installing Docker Machine and checking its version now result in a failure message, even when I repeatedly run the install command below.

I am following the instructions for setting up Docker Machine at this link.

Here is the terminal output after the final reboot:

[root@localhost ~]# base=https://github.com/docker/machine/releases/download/v0.14.0 &&  
>   curl -L $base/docker-machine-$(uname -s)-$(uname -m) >/tmp/docker-machine &&  
>   sudo install /tmp/docker-machine /usr/local/bin/docker-machine
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current  
                                 Dload  Upload   Total   Spent    Left  Speed  
100   617    0   617    0     0    836      0 --:--:-- --:--:-- --:--:--   836
100 26.7M  100 26.7M    0     0  3481k      0  0:00:07  0:00:07 --:--:-- 5962k
[root@localhost ~]# docker-machine version
-bash: docker-machine: command not found
[root@localhost ~]#

Is there some command that I can use to clean all of bash's references so that a clean install can either throw a meaningful error, or hopefully work? Or are there some diagnostic commands that someone can suggest?

I am hoping for a more graceful solution than resorting to re-installing the host operating system and reprovisioning everything in the machine from scratch.

User suggestions:

Per @MichaelHomer's suggestion, I tried the following:

[root@localhost ~]# PATH=/usr/local/bin:$PATH
[root@localhost ~]#

Per @roaima's suggestion, I tried:

[root@localhost ~]# hash -r
[root@localhost ~]# ls -ld /usr/local/bin/docker-machine
-rwxr-xr-x. 1 root root 28034848 Apr 16 16:18 /usr/local/bin/docker-machine
[root@localhost ~]# echo "$PATH"
[root@localhost ~]#

Per @arcsin's suggestion, I typed:

[root@localhost ~]# file /usr/local/bin/docker-machine
/usr/local/bin/docker-machine: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
[root@localhost ~]# /usr/local/bin/docker-machine version
docker-machine version 0.14.0, build 89b8332
[root@localhost ~]#
  • PATH=/usr/local/bin:$PATH? – Michael Homer Apr 16 '18 at 23:34
  • 1
    hash -r should help. If not please ls -ld /usr/local/bin/docker-machine and echo "$PATH" – roaima Apr 16 '18 at 23:34
  • @roaima Thank you. Please see the results added to the end of the OP. – CodeMed Apr 16 '18 at 23:39
  • @MichaelHomer Thank you. Please see the results added to the end of the OP. – CodeMed Apr 16 '18 at 23:39
  • 1
    @CodeMed the hash -r is supposed to fix it... You used that command, but never really called docker-machine directly after using that... Try that. – filbranden Apr 17 '18 at 0:16

For reasons of efficiency, bash maintains a list of the directories in the $PATH where it found each command.

If you run a command that it couldn't find and then add it, you need to tell bash to invalidate its list.

hash -r
  • I puttied into the headless CentOS 7 server again today, and now the docker-machine command is giving the same command not found error described in the OP. But I am able to run the program when I type /usr/local/bin/docker-machine. I typed hash -r again this morning, and then typed hash, which returned a hash table empty message. What do you suggest? – CodeMed Apr 17 '18 at 16:24
  • Sounds like you've not got /usr/local/bin in your $PATH. – roaima Apr 17 '18 at 16:28
  • echo "$PATH" prints out /usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib/jvm/java-1.8.0-openjdk- – CodeMed Apr 17 '18 at 16:30
  • Yep: there's no /usr/local/bin. To make that a permanent change edit one of .profile .bash_profile or .bashrc, find the line that starts PATH= and append /usr/local/bin in the colon-separated list. – roaima Apr 17 '18 at 16:31
  • I googled all 3 files .profile,.bash_profile, and.bashrc. They all seem to be a little different. Also, some documentation says some of these files are specific to each user. I want to set a system-wide setting for all users. Can you be more specific about the steps that should be taken in CentOS 7? – CodeMed Apr 17 '18 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.