When ping is missing on Ubuntu, the command you type and the package you need have different names. Install iputils-ping, not ping:
sudo apt update
sudo apt install -y iputils-ping
That works on Ubuntu Desktop and Server when you have sudo access and working package repositories. If you are already logged in as root, run the APT commands without sudo.
Why apt install ping can fail
ping is the executable; iputils-ping is the Ubuntu package that provides it. In some package metadata, ping is listed as a virtual package rather than an installable package of its own. So sudo apt install ping may report that there is no installation candidate or ask you to choose a provider.
Use the provider package directly:
sudo apt install iputils-ping
If APT cannot locate the package, refresh its package lists first. If that does not help, read the output from apt update for repository or DNS errors. This Ubuntu installation troubleshooting guide can help you investigate broader APT and installation problems.
Minimal Ubuntu images may not include ping by default. That does not mean it is unavailable; it may simply have been left out to keep the image small.
Check that the command is installed
First confirm your shell can find the executable:
command -v ping
After a successful installation, this commonly prints /usr/bin/ping.
Then test the local loopback interface with a fixed number of packets:
ping -c 3 127.0.0.1
The -c 3 option sends three requests and exits. This checks that the command can send and receive local ICMP packets; it does not prove that a remote host is reachable.
For a bounded test against a hostname, try:
ping -c 4 example.com
Without -c, ping normally continues until you stop it with Ctrl+C.
Separate installation problems from network problems
A useful first distinction is whether the executable exists:
-
command -v pingprints nothing: the package may be missing, or the shell cannot find the executable. - Ping works to an IP address but not a hostname: investigate name resolution.
- The command runs, but requests time out: the destination, route, or a firewall may not be answering ICMP.
- The command exists but a container reports
Operation not permitted: the container’s runtime security settings or capabilities may prevent sending ICMP packets.
A timeout does not mean ping is uninstalled. And a successful ping does not prove that a website, SSH server, or application is healthy: it only shows that ICMP traffic succeeded to that destination at that time. Test the service you care about separately.
Add ping to an Ubuntu Docker image
If an application container needs ping, add the package to its Dockerfile and rebuild the image. Installing it manually in a running container does not make that change part of the image, so it may disappear when the container is replaced.
FROM ubuntu:24.04
RUN apt-get update \
&& apt-get install -y --no-install-recommends iputils-ping \
&& rm -rf /var/lib/apt/lists/*
Build the image from the directory containing the Dockerfile:
docker build -t ubuntu-with-ping .
ubuntu:24.04 is an example base image; choose the version that fits your application. The package makes the command available in the image, but it does not guarantee that the container can send ICMP packets at runtime. Runtime permissions and network policy still matter. If you are setting up Docker on an Ubuntu host, see this guide to installing Docker Engine on Ubuntu.
A quick diagnostic sequence
When a ping test fails, check the stages separately:
-
Is the executable present? Run
command -v ping. -
Can it reach loopback? Run
ping -c 3 127.0.0.1. - Does the hostname resolve? Compare a hostname test with a test to a known IP address.
- Is ICMP allowed along the path? A destination or firewall may block or ignore ping requests.
-
Is this happening in a container? Check runtime permissions and policy if the error says
Operation not permitted.
This keeps package installation, DNS, network reachability, and container permissions from getting conflated. A successful check at one stage does not guarantee the next one will succeed.
I originally published a more detailed version of this guide on the SSHFlow blog.
I'm also building SSHFlow — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.
Top comments (1)
tr.ee/dev-to