It’s really easy to install. Just open up a terminal window on your Raspberry Pi and type the following at the command line,
$ sudo apt-get install python-pip
$ pip install speedtest-cli
This will install pip — a package management system for Python — if you don’t already have it installed, and then the speedtest-cli package from the pip repositories.
Then download and adjust this script accordingly.