At the end of .bashrc file I added these lines to set path to foo folder in my home directory:
PATH = $PATH:/home/username/foo
export PATH;
Then I typed in bash:
source .bashrc
These produced error:
bash: PATH: command not found
I am using Debian Squeeze. In a similar question here it was advised to modify /etc/login.defs. I don't want to do this as in the very login.defs it is written:
add the rest [of your paths] in the shell startup files
How to add folder foo to PATH in .bashrc?
You are using the wrong syntax. Drop the spaces:
export PATH=$PATH:/home/username/foo
Regarding /etc/login.defsor any other global configuration: Well, it is global configuration, so probably a bad idea to add paths within your $HOME directory there. ;)
Just use the following line in your .bashrc
export PATH=/home/username/foo:$PATH
There are differences in syntax between the one used on mac and CentOS, however on CentOS and RedHat the following syntax is being used.
export PATH="/path/directory:$PATH"
then do
source .bashrc
I am not sure about other distributions of Linux but it will work on CentOS and RedHat.
Related
I installed Hadoop and now it works with command /usr/local/hadoop/bin/hadoop.
Where and how should I add this path to make command hadoop work without a full path to file? I already tried .bashrc and /etc/environment, but it didn't help.
You need to add it to your PATH environment variable. PATH is used to find programs to run in the shell.
To see what your current PATH is you can type
$ echo $PATH
When you update the PATH variable you want to make sure you don't delete previous entries.
$ PATH=$PATH:/usr/local/hadoop/bin
How can I change the $PATH variable in Debian? I tried to change /etc/profile but this affected only normal users (and yes, I added path to BOTH user's and root's paths).
After that I tried to edit /root/.profile and then /root/.bashrc also ...
Neither worked. Do you know where could be problem?
This is set in the /etc/login.defs on debian 6.0 .
These are the lines you have to edit:
# *REQUIRED* The default PATH settings, for superuser and normal users.
#
# (they are minimal, add the rest in the shell startup files)
ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV_PATH PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
EDIT:
I forgot to put where I found the solution: https://serverfault.com/questions/166383/how-set-path-for-all-users-in-debian
Modify /etc/environment to include a line like this:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
If you are using a graphical display manager / GUI (a.k.a not just a shell or terminal) changing the /etc/profile, ~/.bashrc or other file will not change the PATH variable.
In this case you have to create the file: ~/.xsessionrc file and add something like this:
export PATH="$PATH:/sbin"
(depending on the path you want to add)
For more info: https://wiki.debian.org/EnvironmentVariables
NOTE for Debian 10, check out this solution first if you get command not found:
su - root instead of su root
https://unix.stackexchange.com/questions/482569/debian-10-buster-update-grub-command-not-found
Simple way for me was to create file /etc/default/su with content
ALWAYS_SET_PATH yes
so I do not have to meddle with system files directly.
I want to add multiple path in $path variable like java path and php path . how to do that in linux?
I am doing something in bash_profile like :
PATH=$JAVA_HOME/bin:$PATH:/usr/java/jdk1.7.0_45/bin/:$AWS_AUTO_SCALING_HOME/bin
$PATH can have several paths separated by a colon (:). E.g.:
export PATH=/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/myuser/bin
Set the $PATH environment variable to include the directory where you installed the bin directory with shell scripts and two consecutive export entries as in example.
Example:
export ANT_HOME=/path/to/ant/dir
export PATH=${PATH}:${ANT_HOME}/bin:${JAVA_HOME}/bin
To make them permanent entries update the bash_profile file.
One way to add multiple executables to the $PATH variable is:
export PATH=/path/to/executable1:\
/path/to/executable2:\
/path/to/executable3:\
/path/to/executable4
If a $PATH already exists in .bash_profile, and you want them to take precedence over executables (like java and php), you can do:
export PATH=$PATH:/path/to/executable1:\
/path/to/executable2:\
/path/to/executable3:\
/path/to/executable4
If the path to any executable contains whitespaces, add the part / ... executableX in quotes.
Once you're done making changes in your bash_profile, source the file in a terminal session so that changes are effective immediately:
source .bash_profile
Open Terminal and Type sudo gedit /etc/profile to open system path file
Go to Bottom
VARIABLE_NAME1=/your/path/to/location1
VARIABLE_NAME2=/your/path/to/location2
PATH=$PATH:$VARIABLE_NAME1:\$VARIABL3_NAME2
export PATH
Logout from user and Relogin
If you're on a Mac, the best way in my opinion would be following Chamindu's answer with a slight tweak. using nano or vim whichever you prefer, but I'll use nano as it's easier for most people.
Open Terminal and Type nano ~/.bash_profile to open bash profile.
At the top, type or copy and paste the following:
FLUTTER="/Users/MyUsername/development/flutter/bin"
VSCODE="/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
PATH=$PATH:$FLUTTER:\$VSCODE
export PATH
If you're using nano as I suggested, do a control + x on your keyboard to exit.
press Y to save your changes.
In the terminal type source ~/.bash_profile to refresh your bash profile/environment variables.
Now you can navigate to any directory and call the files in your path.
Note:
Swap out FLUTTER and VSCODE for your variable names of choice.
You would only need to use sudo if you're not using the admin account.
sudo CPATH=/usr/include/linux/:/usr/src/linux-headers-5.17.0-1-common/include/linux/ vmware-modconfig --console --install-all
I have first executed the command: export LD_LIBRARY_PATH=/usr/local/lib
Then I have opened .bash_profile file: vi ~/.bash_profile.
In this file, I put:
LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH
Then if the terminal is closed and restarted, typing echo $LD_LIBRARY_PATH displays no result.
How to set the path permanently?
You should add more details about your distribution, for example under Ubuntu the right way to do this is to add a custom .conf file to /etc/ld.so.conf.d, for example
sudo gedit /etc/ld.so.conf.d/randomLibs.conf
inside the file you are supposed to write the complete path to the directory that contains all the libraries that you wish to add to the system, for example
/home/linux/myLocalLibs
remember to add only the path to the dir, not the full path for the file, all the libs inside that path will be automatically indexed.
Save and run sudo ldconfig to update the system with this libs.
Keep the previous path, don't overwrite it:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/
You can add it to your ~/.bashrc:
echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/your/custom/path/' >> ~/.bashrc
Add
LD_LIBRARY_PATH="/path/you/want1:/path/you/want/2"
to /etc/environment
See the Ubuntu Documentation.
CORRECTION: I should take my own advice and actually read the documentation. It says that this does not apply to LD_LIBRARY_PATH: Since Ubuntu 9.04 Jaunty Jackalope, LD_LIBRARY_PATH cannot be set in $HOME/.profile, /etc/profile, nor /etc/environment files. You must use /etc/ld.so.conf.d/.conf configuration files.* So user1824407's answer is spot on.
Alternatively you can execute program with specified library dir:
/lib/ld-linux.so.2 --library-path PATH EXECUTABLE
Read more here.
The file .bash_profile is only executed by login shells. You may need to put it in ~/.bashrc, or simply logout and login again.
For some reason no one has mentioned the fact that the bashrc needs to be re-sourced after editing. You can either log out and log back in (like mentioned above) but you can also use the commands: source ~/.bashrc or . ~/.bashrc.
Put export LD_LIBRARY_PATH=/usr/local/lib in ~/.bashrc [preferably towards end of script to avoid any overrides in between, Default ~/.bashrc comes with many if-else statements]
Post that whenever you open a new terminal/konsole, LD_LIBRARY_PATH will be reflected
Go to the home folder and edit .profile
Place the following line at the end
export LD_LIBRARY_PATH=<your path>
Save and Exit.
Execute this command
sudo ldconfig
You could try adding a custom script, say myenv_vars.sh in /etc/profile.d.
cd /etc/profile.d
sudo touch myenv_vars.sh
sudo gedit myenv_vars.sh
Add this to the empty file, and save it.
export LD_LIBRARY_PATH=/usr/local/lib
Logout and login, LD_LIBRARY_PATH will have been set permanently.
I do the following in Mint 15 through 17, also works on ubuntu server 12.04 and above:
sudo vi /etc/bash.bashrc
scroll to the bottom, and add:
export LD_LIBRARY_PATH=.
All users have the environment variable added.
In Ubuntu 20.04 Linux this is just not obvious and straight forward as it should be.
I will attempt to make it simple for anyone who is pulling out their hair just like I was with my Ubuntu 20.04.3 Linux.
Start by identifying the path where your library files' folder is located. In my case, the *.so files that I was working with were located in a folder called libs and this folder's path in my Ubuntu box is /usr/lib
So now I want to add the path /usr/lib to LD_LIBRARY_PATH such that when I run echo $LD_LIBRARY_PATH in my Ubuntu terminal I will be able to see the path /usr/lib echoed as shown below;
joseph$ echo $LD_LIBRARY_PATH
:/usr/lib
Here are the steps I used
Open terminal in Ubuntu 20.04 Linux box
Change path to /etc/ld.so.conf.d/ by running cd /etc/ld.so.conf.d/
Create a file with a *.conf extension at the end with a text editor
like e.g. vim or gedit in my case I created it as follows sudo gedit my_project_libs.conf
Inside the .conf file that I created named my_project_libs.conf
I added the path to my libs by adding this line export
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib
Thereafter, I then run gedit ~/.bash_profile to open the
~/.bash_profile file so that I can add inside it this line export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib which includes the path to the folder with my libraries /usr/lib that I want
included in LD_LIBRARY_PATH
I also ran gedit ~/.bashrc to open the
~/.bashrc file so that I can add inside it this line export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib which includes the path to the folder with my libraries /usr/lib that I want
included in LD_LIBRARY_PATH
When you are done adding the line in step 5, save and close.
In your terminal, type the following sudo ldconfig and press
enter on your keyboard.
Close all your open terminals that you were using then open a new terminal session and run echo $LD_LIBRARY_PATH If you see the path you added is echoed back, you did it right.
In my case, this is what I see :/usr/lib when I run echo $LD_LIBRARY_PATH in my newly opened Ubuntu terminal session
joseph$ echo $LD_LIBRARY_PATH
:/usr/lib
That's how I got it to work for me in my Ubuntu 20.04.3 Linux box.
Everyone seems to be missing the forest for the trees.
The real answer is that '~/.bash_profile' is by default only sourced for LOGIN SHELLS.
The bash config file you are probably looking for if you are starting and closing terminals from your desktop GUI is '~/.bashrc', which is the file sourced by default when starting interactive, non-login shells.
https://apple.stackexchange.com/questions/51036/what-is-the-difference-between-bash-profile-and-bashrc
On a Mac one can run any downloaded executable in the terminal using just the executable name. On Linux, such as Ubuntu, by default one will have to specify the directory to run in.
Mac example: sbt
Linux example: ./sbt
What do I need to set in Linux so that I don't need the ./ in front of the executable?
This should work:
PATH=$PATH:.
or in bash:
PATH+=:.
You can define an alias in your .bashrc file if it is an often used file. Or just add the directory in which your files is located to your $PATH var.
Copy your script in /usr/local/bin