Change Path Permanently on Ubuntu

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

  1. /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.

  2. /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.

  3. /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.

  4. /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.

  5. /etc/<shell>.<shell>rc. Shell script. This is a poor choice because it is single shell specific. Used in non-login mode.

User session

  1. ~/.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.

  2. ~/.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.

  3. ~/.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.

  4. ~/.<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

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:

  1. Append something to your PATH

    export PATH=$PATH:/your/new/path/here
  2. 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


  1. /etc/environment List of unique assignments. Perfect for adding system-wide directories like /usr/local/something/bin to PATH
    variable or defining JAVA_HOME.
  2. /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.
  3. /etc/profile and /etc/profile.d/* Shell script. This is a good choice for shell-only systems. Those files are read only by shells.
  4. /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


  1. ~/.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
    including HOME or PATH so it has limited use.
  2. ~/.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.
  3. ~/.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.
  4. ~/.<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



Leave a reply



Submit