In this tutorial, we will guide you through the process of adding
~/.local/bin to your PATH in WSL Ubuntu 18.04. This task is crucial for developers who want to run scripts or programs that are located in
~/.local/bin directory without having to type the full path to the executable.
~/.local/bin to your PATH in WSL Ubuntu 18.04, open the
.bashrc file in a text editor, scroll to the bottom, and add the line:
export PATH="$HOME/.local/bin:$PATH". Save the changes, either restart your terminal or run
source ~/.bashrc to apply the changes. This allows you to run executables from
~/.local/bin without specifying the full path.
What is PATH?
PATH is an environment variable in Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located. In general, each executing process or user session has its own PATH setting.
Why Add ~/.local/bin to PATH?
~/.local/bin to your PATH is convenient because it allows you to run executables from that directory no matter what your current working directory is. This can be particularly useful if you have scripts or programs in
~/.local/bin that you want to be able to run from anywhere.
Open your terminal by pressing
Ctrl + Alt + T or by searching for it in the Ubuntu dashboard.
Navigate to Home Directory
Navigate to your home directory by running the following command:
cd command changes the current directory. The
~ symbol represents the home directory of the current user.
Open .bashrc File
.bashrc file in a text editor. In this example, we’ll use
nano, but you can use any text editor you prefer:
.bashrc file is a script that runs every time you open a new terminal window. It’s used to configure your terminal session.
Add ~/.local/bin to PATH
Scroll to the bottom of the file and add the following line:
This line adds
~/.local/bin to the beginning of your PATH. The
$HOME variable is a reference to your home directory, and
$PATH is your current PATH.
Save and Exit
Save the changes by pressing
Ctrl + X, then press
Y to confirm the save, and finally press
Enter to exit.
To apply the changes, either restart your terminal or run the following command in the current terminal session:
source command reads and executes commands from the file specified as its argument in the current shell environment.
After following these steps,
~/.local/bin will be added to your PATH, allowing you to run executables from that directory without specifying the full path. This is a small but significant enhancement to your workflow, especially if you frequently use scripts or programs located in
.bashrc file is specific to the Bash shell. If you are using a different shell, such as Zsh, you may need to modify a different configuration file, such as
.zshrc, instead. For more information about PATH and other environment variables, you can visit the Ubuntu documentation.
We hope you found this tutorial helpful. If you have any questions or run into any issues, please feel free to leave a comment below.
You can check your current PATH by running the following command in your terminal:
echo $PATH. This will display a list of directories separated by colons, indicating the current PATH.
Yes, you can add multiple directories to your PATH by separating them with colons. For example, if you want to add
/usr/local/bin to your PATH, you would use the following line:
To remove a directory from your PATH, you need to edit the
.bashrc file again and remove the corresponding line that adds the directory to the PATH. After saving the file, you will need to either restart your terminal or run
source ~/.bashrc for the changes to take effect.
Yes, you can add directories to your PATH that are located outside your home directory. Simply replace
~/.local/bin in the command with the full path to the directory you want to add. For example, if you want to add
/opt/bin to your PATH, you would use the following line:
No, adding directories to your PATH only affects the current user’s environment. System-wide executables are typically located in directories that are already in the system’s default PATH. If you want to add directories for all users, you will need to modify the system-wide configuration file instead.