How to Test Internet Speed from Terminal in Ubuntu Linux
Developed by Ookla, Speedtest CLI is a command-line tool that is tailored for system administrators and developers, and command-line enthusiasts. It provides the capability of checking the internet speeds straight from your Linux terminal.
Speedtest CLI allows you to do the following:
Check the bandwidth performance including metrics such as download, upload, and packet loss. Check the connection from your PC or even a remote server and IoT devices such as Raspberry Pi. Configure scripts to collect speed test results over a period of time. Save results in CSV or JSON.
Installation Requirements
Speedtest-cli works with Python 2.4-3.7 For best results, ensure that you have Python 3.6 and later since older versions have been deprecated.
How to install Speedtest-cli
There are various ways of installing the Speedtest-cli tool. Let’s briefly cover each of them.
Install Speedtest-cli using the APT package manager
This is the easiest and most straightforward way of installing Speedtest-cli. To start off, use the curl command to setup the Speedtest-cli repository.
$ curl -s https://install.speedtest.net/app/cli/install.deb.sh | sudo bash
Once the repository is set up, use the APT package manager to install Speedtest-cli as follows.
$ sudo apt install speedtest-cli
Install Speedtest-cli using Python script
The alternative way of installing Speedtest-cli is to download and execute the Speedtest-cli Python script. To start off, download the script from GitHub using the wget command as shown.
$ wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
Once the download is complete, you can verify its presence using the ls command as shown.
$ ls -l | grep speedtest
Finally, execute permissions to the speedtest-cli Python script using the chmod command.
$ sudo chmod +x speedtest-cli
Then move the speedtest-cli script to the /usr/bin path.
$ sudo mv speedtest-cli /usr/bin
Check version of Speedtest-cli
To check the version of the Speedtest-cli tool, run the command:
$ speedtest-cli --version
Testing the internet connection speed using Speedtest-cli
Now, let’s begin testing the speed of our internet connection. You can run the speedtest-cli command in its basic form without any arguments as shown.
$ speedtest-cli
As you can see, the script begins by retrieving the testing configuration from speedtest.net and identifies your ISP. It then retrieves a list of possible servers, selects the best server, and proceeds to perform both the download and upload speed tests, and prints out the results on the terminal.
You can share the bandwidth results with others using the –share option.
$ speedtest-cli --share
A URL containing the results of the speed test is provided at the very end. This contains a PNG image of the speed test results.
http://www.speedtest.net/result/11602946461.png
Copy and paste the URL on a browser and hit ENTER to view the speed test statistics.
If you just want simplified output that only displays the download and upload speeds, use the –simple option.
$ speedtest-cli --simple
To print a list of possible servers based on physical distance, use the –list option.
$ speedtest-cli --list
If the output contains servers from different regions, use the grep command to filter the output based on your preferred server. Here, we are listing servers located in Nairobi.
$ speedtest-cli --list | grep -i Nairobi
For more command options, use the –help option.
$ speedtest-cli --help