Steps to setup Locust on Linux
In this post, I will be taking you through end to end steps to set up Locust environment on Linux Machine without using Docker.
This post is also a resource to my Udemy course Performance Testing using Locust.
To visit more such posts, follow: #PerformanceTesting #Locust
Step 1 - Avail Linux machine or AWS EC2 Linux instance
Step 2 - Install Python 3.8 on Linux machine
Step 3 - Install a virtual environment for python 3.8
Step 4 - Activate the virtual environment for Locust
Step 5 - Install locust in the virtual environment
As the heading says, you need to have a Linux machine. Else, follow this post, connect to AWS EC2 Linux instance.
Follow steps here to install Python 3.8 on Linux
Once python is installed verify python version as below:
As you can see there are two versions of python on the machine. One is the default shipped version, which is 2.7 and the other we just installed. We did not add 3.8 to /usr/bin/python as we did not want to disturb the global environment which may be a dependency on other applications. Hence to install Locust's latest version on 3.8, we need to create an isolated environment called the virtual environment of python 3.8. Let's do that in the next step.
Let's create one directory for locust project & make it a virtual environment
To install a virtual environment, give below command
python3.8 -m pip install --user virtualenv
Once a virtual environment is installed, we will point to the created directory as a virtual environment.
virtualenv <name of directory where virtualenv is to be created>
With the above command, python and pip get copied to the environment, and directory structure is created under mylocustproject .
Activate this project as a virtual environment using python 3.8. Give command:
As you can see, instead of working in a global shell, now we will work in the shell of our virtual environment. Also, notice the version of python returned which is the one we want for the latest locust version.
Let's proceed to install Locust with python 3.8
Now we are finally at the step of installing locust. It can be installed using PIP, and the package is available in PyPy.
pip install locust
Once the locust is installed successfully, locust command is available on the shell: