0

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"
/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64/bin:/root/bin
[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 ~]#
CodeMed
  • 5,079
  • 45
  • 100
  • 147

1 Answers1

1

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
roaima
  • 107,089
  • 14
  • 139
  • 261
  • 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-1.8.0.151-1.b12.el7_4.x86_64/bin:/root/bin` – 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
  • See [How to set path for all users on CentOS 7](https://unix.stackexchange.com/q/409126/100397) – roaima Apr 17 '18 at 16:58
  • To accomplish what you said, I had to instead use this link and this other link. – CodeMed Apr 17 '18 at 17:14
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/76176/discussion-between-roaima-and-codemed). – roaima Apr 17 '18 at 18:28