Automating Frappe Bench Start in WSL with some simple steps

Starting your Frappe Bench
in Windows Subsystem for Linux (WSL) can involve a few repetitive steps. This blog post will show you how to automate this process, saving you time and effort.
Every time you want to work on your Frappe
project, you likely have to:
WSL
distribution (e.g., Ubuntu
). virtual environment
. Frappe Bench
directory. bench start
. This process can be repetitive. However, we can automate it using the .bashrc
file while also gaining a better understanding of how .bashrc
works.
Bash
Script and PATH
We'll use a simple Bash script and leverage the PATH
environment variable to streamline this process.
.bashrc
?The .bashrc
file is a script that runs automatically whenever you start a new Bash shell session in Linux
, including WSL (Windows Subsystem for Linux). It is located in your home directory:
~/.bashrc
First, create a script named frappe_start.sh
(or any name you prefer) in a convenient location within your WSL filesystem. I recommend creating a dedicated directory for your scripts. In this example, we'll use ~/customScript
:
mkdir ~/customScript
cd ~/customScript
nano frappe_start.sh
Now, paste the following content into frappe_start.sh
, making sure to replace /mnt/c/Users/USER
with your actual Windows user path as it appears in WSL
:
#!/bin/bash
cd
source ./env/bin/activate
cd frappe-bench/
bench start
Save
the file and make it executable
:
chmod +x frappe_start.sh
Check the location using pwd
command and copy the path
for the next step
pwd
Example Usage:
sab@DESKTOP-KANOFJB:~/customScript$ pwd
/home/sab/customScript
PATH
The PATH
environment variable tells your shell where to look for executable files. We need to add the directory containing our script to PATH
. To make this change persistent, we will modify the .bashrc
file.
Open the .bashrc
file:
nano ~/.bashrc
Add the following line at the end of the .bashrc
file, replacing /home/sab/customScript
with the actual path to your customScript
directory within WSL:
export PATH=$PATH:/home/sab/customScript # **REPLACE THIS WITH YOUR ACTUAL PATH**
Save the .bashrc
file and apply the changes:
source ~/.bashrc
Now, simply open your WSL terminal and type:
frappe_start.sh
Or, if you named your script frappe_start
:
frappe_start
Your Frappe Bench should start automatically!
✅ WSL Paths: Remember that paths within WSL differ from Windows paths. Use the WSL path (e.g., /mnt/c/Users/USER
) rather than the Windows path (e.g., C:\Users\USER
).
✅ .bashrc
Persistence: The .bashrc
file is crucial for making the PATH
change persistent across WSL sessions.
✅ Script Location: Choose a convenient location for your script. Keeping it in a dedicated directory like ~/customScript
is a good practice.