change PATH permanently on Ubuntu
Add
export PATH=$PATH:/home/me/play
to your ~/.profile
and execute
source ~/.profile
in order to immediately reflect changes to your current terminal instance.
How to permanently set $PATH on Linux/Unix
There are multiple ways to do it. The actual solution depends on the purpose.
The variable values are usually stored in either a list of assignments or a shell script that is run at the start of the system or user session. In case of the shell script you must use a specific shell syntax and export
or set
commands.
System wide/etc/environment
List of unique assignments. Allows references. Perfect for adding system-wide directories like /usr/local/something/bin
to PATH
variable or defining JAVA_HOME
. Used by PAM and systemd.
/etc/environment.d/*.conf
List of unique assignments. Allows references. Perfect for adding system-wide directories like /usr/local/something/bin
to PATH
variable or defining JAVA_HOME
. The configuration can be split into multiple files, usually one per each tool (Java, Go, and Node.js). Used by systemd that by design do not pass those values to user login shells.
/etc/xprofile
Shell script executed while starting X Window System session. This is run for every user that logs into X Window System. It is a good choice for PATH
entries that are valid for every user like /usr/local/something/bin
. The file is included by other script so use POSIX shell syntax not the syntax of your user shell.
/etc/profile
and /etc/profile.d/*
Shell script. This is a good choice for shell-only systems. Those files are read only by shells in login mode.
/etc/<shell>.<shell>rc
. Shell script. This is a poor choice because it is single shell specific. Used in non-login mode.
User session~/.pam_environment
. List of unique assignments, no references allowed. Loaded by PAM at the start of every user session irrelevant if it is an X Window System session or shell. You cannot reference other variables including HOME
or PATH
so it has limited use. Used by PAM.
~/.xprofile
Shell script. This is executed when the user logs into X Window System system. The variables defined here are visible to every X application. Perfect choice for extending PATH
with values such as ~/bin
or ~/go/bin
or defining user specific GOPATH
or NPM_HOME
. The file is included by other script so use POSIX shell syntax not the syntax of your user shell. Your graphical text editor or IDE started by shortcut will see those values.
~/.profile
, ~/.<shell>_profile
, ~/.<shell>_login
Shell script. It will be visible only for programs started from terminal or terminal emulator. It is a good choice for shell-only systems. Used by shells in login mode.
~/.<shell>rc
. Shell script. This is a poor choice because it is single shell specific. Used by shells in non-login mode.
Notes
/etc/environment
List of unique assignments. Allows references. Perfect for adding system-wide directories like /usr/local/something/bin
to PATH
variable or defining JAVA_HOME
. Used by PAM and systemd.
/etc/environment.d/*.conf
List of unique assignments. Allows references. Perfect for adding system-wide directories like /usr/local/something/bin
to PATH
variable or defining JAVA_HOME
. The configuration can be split into multiple files, usually one per each tool (Java, Go, and Node.js). Used by systemd that by design do not pass those values to user login shells.
/etc/xprofile
Shell script executed while starting X Window System session. This is run for every user that logs into X Window System. It is a good choice for PATH
entries that are valid for every user like /usr/local/something/bin
. The file is included by other script so use POSIX shell syntax not the syntax of your user shell.
/etc/profile
and /etc/profile.d/*
Shell script. This is a good choice for shell-only systems. Those files are read only by shells in login mode.
/etc/<shell>.<shell>rc
. Shell script. This is a poor choice because it is single shell specific. Used in non-login mode.
~/.pam_environment
. List of unique assignments, no references allowed. Loaded by PAM at the start of every user session irrelevant if it is an X Window System session or shell. You cannot reference other variables includingHOME
orPATH
so it has limited use. Used by PAM.~/.xprofile
Shell script. This is executed when the user logs into X Window System system. The variables defined here are visible to every X application. Perfect choice for extendingPATH
with values such as~/bin
or~/go/bin
or defining user specificGOPATH
orNPM_HOME
. The file is included by other script so use POSIX shell syntax not the syntax of your user shell. Your graphical text editor or IDE started by shortcut will see those values.~/.profile
,~/.<shell>_profile
,~/.<shell>_login
Shell script. It will be visible only for programs started from terminal or terminal emulator. It is a good choice for shell-only systems. Used by shells in login mode.~/.<shell>rc
. Shell script. This is a poor choice because it is single shell specific. Used by shells in non-login mode.
Notes
GNOME on Wayland starts a user login shell to get the environment. It effectively uses the login shell configurations ~/.profile
, ~/.<shell>_profile
, ~/.<shell>_login
files.
Man pages- environment
- environment.d https://linux.die.net/man/1/environment.d
- bash
- dash
Distribution-specific documentation- Ubuntu
- Arch Linux
Related
- Ubuntu
- Arch Linux
Related
Difference between Login Shell and Non-Login Shell?
How can I edit the $PATH on linux?
To permanently store your path, you have a few options.
I suggest you read the Ubuntu community wiki on Environment Variables but the short answer is the best place is ~/.profile
for your per-user PATH setting or /etc/profile
for global settings.
Change PATH:
Append something to your PATH
export PATH=$PATH:/your/new/path/here
Override your PATH (save backup before!)
export PATH=:/your/new/path/here:/another/new/path/here
How to add flutter SDK to PATH permanently on ubuntu linux?
Just edit the .bashrc file in your home directory and add
export PATH="$PATH:$HOME/[path to the directory you have installed flutter]/flutter/bin"
For example:
`export PATH="$PATH:$HOME/Documents/development/flutter/bin"`
Save the file and reopen the terminal
Where is PATH variable set in Ubuntu?
Grzegorz Żur's answer to another question captures it brilliantly. Unfortunately it was hidden away among many other answers.
There are multiple ways to do it. The actual solution depends on the
purpose.The variable values are usually stored in either a list of assignments
or a shell script that is run at the start of the system or user
session. In case of the shell script you must use a specific shell
syntax.System wide
/etc/environment
List of unique assignments. Perfect for adding system-wide directories like/usr/local/something/bin
toPATH
variable or definingJAVA_HOME
./etc/xprofile
Shell script executed while starting X Window System session. This is run for every user that logs into X Window
System. It is a good choice forPATH
entries that are valid for
every user like/usr/local/something/bin
. The file is included by
other script so use POSIX shell syntax not the syntax of your user
shell./etc/profile
and/etc/profile.d/*
Shell script. This is a good choice for shell-only systems. Those files are read only by shells./etc/<shell>.<shell>rc
. Shell script. This is a poor choice because it is single shell specific.
Also, /etc/environment
is not a script file, but rather consists of assignment expressions, one per line. Since this file stores the system-wide locale and path settings, it is most oft quoted choice.
Using /etc/profile
is not preferred. It exists only to point to /etc/bash.bashrc
and to collect entries from /etc/profile.d
User session
~/.pam_environment
. List of unique assignments. Loaded by PAM at the start of every user session irrelevant if it is an X
Window System session or shell. You cannot reference other variable
includingHOME
orPATH
so it has limited use.~/.xprofile
Shell script. This is executed when the user logs into X Window System system. The variables defined here are visible to
every X application. Perfect choice for extendingPATH
with values
such as~/bin
or~/go/bin
or defining user specificGOPATH
or
NPM_HOME
. The file is included by other script so use POSIX shell
syntax not the syntax of your user shell. Your graphical text editor
or IDE started by shortcut will see those values.~/.profile
Shell script. It will be visible only for programs started from terminal or terminal emulator. It is a good choice for
shell-only systems.~/.<shell>rc
. Shell script. This is a poor choice because it is single shell specific.
How to set Java environment path in Ubuntu
set environment variables as follows
Edit the system Path file /etc/profile
sudo gedit /etc/profile
Add following lines in end
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
Then Log out and Log in ubuntu for setting up the paths...
add permanet PATH in ubuntu
First Solution:
Try replacing ~/mytools/my_scripts
with /home/your_username/mytools/my_scripts
in your .profile
OR use $HOME
variable instead like this.
PATH="$HOME/mytools/my_scripts:$PATH"
Second Solution
Copy all of your scripts to /usr/bin
cp ~/mytools/my_scripts/* /usr/bin/
Related Topics
Limiting Memory Usage in R Under Linux
"Max Open Files" for Working Process
Creating a Bootable Iso Image with Custom Bootloader
Vim Configuration for Linux Kernel Development
How to Get the Name of the Current Git Branch into a Variable in a Shell Script
What Is Path on a MAC (Unix) System
Why Is the Probe Method Needed in Linux Device Drivers in Addition to Init
Single File Volume Mounted as Directory in Docker
Nginx: Serve Multiple Laravel Apps with Same Url But Two Different Sub Locations in Linux
Bash Copy All Files Except One
Pack Shared Libraries into the Elf
Init Function Invocation of Drivers Compiled into Kernel
Send Mail from Linux Terminal in One Line