If you're running an extremely minimal install of Ubuntu or using Ubuntu as a Docker, then you may encounter such a situation where the ping command won't be installed.
And when you try to use the ping command, it will throw the following error:
So in this tutorial, I will walk you through how you can install the ping command in Ubuntu.
How to install ping in Ubuntu
Even if you try to install ping using
sudo apt install ping, it will show an error saying
Package 'ping' has no installation candidate:
root@LU-Docker:/# apt install ping Reading package lists... Done Building dependency tree... Done Reading state information... Done Package ping is a virtual package provided by: inetutils-ping 2:2.2-2 iputils-ping 3:20211215-1 You should explicitly select one to install. E: Package 'ping' has no installation candidate
The reason is simple! There is no package called
ping in apt repo and this is why it gave you an error.
And to install ping, you have to install a package called
iputils-ping using the following command:
sudo apt install iputils-ping
Once done, you can use the ping command to check whether the host is up or not:
For example, here, I used LU as the target:
root@LU-Docker:/# ping learnubuntu PING learnubuntu (192.168.1.8) 56(84) bytes of data. 64 bytes from Learnubuntu.bbrouter (192.168.1.8): icmp_seq=1 ttl=63 time=0.328 ms 64 bytes from Learnubuntu.bbrouter (192.168.1.8): icmp_seq=2 ttl=63 time=0.468 ms 64 bytes from Learnubuntu.bbrouter (192.168.1.8): icmp_seq=3 ttl=63 time=0.483 ms 64 bytes from Learnubuntu.bbrouter (192.168.1.8): icmp_seq=4 ttl=63 time=0.487 ms
To stop the ping, you can use
Ctrl + c.
There is a similar traceroute command that lets you trace the path instead of just pinging it.
Learn how to use the ping command
After the installation, learning the basics of a ping command is a good idea.
And if you don't know, it can also be used apart from checking whether the host is up or not. Here are various ways to use the ping command:
I hope you will find this guide helpful.