How to fix "bash: hostname: command not found" error

Endrit Qerreti

Endrit Qerreti

If you got the error "bash: hostname: command not found" on your terminal, it simply means that the command that you were issuing it wasn't a valid command.

This error happens when you are executing the hostname command.

hostname command allows you to show your system's hostname, but not only. You can also change your server's or machine's hostname via this command.

When hostname command doesn't work, it could be that you are missing the required package inetutils which contains the hostname tool.

In this tutorial, you will learn how to fix "bash: hostname: command not found" error on Arch Linux, and Arch Linux based distros.

Step 1 - Update your system

Before installing the required package in order for the hostname command to work, make sure that your system's package index is updated.

We are using Arch Linux for this tutorial, so to update Arch Linux we need to use pacman.

sudo pacman -Syu

Step 2 - Install inetutils

hostname is part of inetutils package, this package contains a lot of network tools that you can use on your system, one of them is the hostname tool.

In order to be able to use the hostname command, you must have inetutils nstalled on your system.

inetutils is available on the core repository of Arch Linux, which means you can easily install inetutils via pacman.

To install inetutils, simply run the command below.

sudo pacman -S inetutils

Next, enter your password to authenticate

After authenticating, confirm that you want to install inetutils. To do this, all you have to do is press Y, and enter.

And inetutils should now be installed on your system.

Step 3 - Run hostname Command

Now that inetutils package is installed on your system, the error "bash: hostname: command not found" should also be fixed.

To verify that the error is fixed, you can proceed to run the hostname command.

hostname

And it will show you your machine's hostname as shown in the screenshot below.

Conclusion

In this tutorial, you learned how to fix the error "bash: hostname: command not found" by simply installing the required package inetutils.

inetutils contains network tools and hostname tool too, which means that if inetutils is not installed on your system, then you won't be able to use the hostname command.

We used Arch Linux for this tutorial. However, if you are getting a similar error on another Arch Based distro, like "Manjaro", make sure that inetutils is installed on your system.