Not able to permanently set environmental variable PATH - linux

I want to add the path to pycharm.sh to PATH (Pycharm community Edition 5.0.2), which is stored in /opt/pycharm-community-5.0.2/bin. At first I added the following line to /etc/environment, which was an empty file before:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/pycharm-community-5.0.2/bin"
Afterward I tried to start Pycharm via terminal, without success:
$ pycharm
bash: pycharm: command not found.
My next step was to change the value of PATH inside the first if statement in /etc/profile as follows:
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/pycharm-community-5.0.2/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/pycharm-community-5.0.2/bin"
fi
export PATH
I restarted the system after each step, but I still the receive the same error message.
Is there another way to permanently set the variable? What am I doing wrong?

Your executable filename is pycharm.sh, not pycharm. Try typing that instead.
You could also try which pycharm.sh, which attempts to locate given command using PATH environment variable, to see that your configuration works.

Related

automating the linking of library to the llc exe

Hi Linux noob here,
I wanted to link the LLC.exe with one of the shared libraries , the thing what I do is in order to make the llc -c to work I have to link them like these
PATH="/usr/local/bin:/usr/bin:/bin:/opt/noob/bin"
LD_LIBRARY_PATH="/opt/noob/lib"
export PATH LD_LIBRARY_PATH
If I give these commands it works , Now I want to automate this so I wrote a this in a .sh (bash script ) file and called it in rc.local file but it does-not work, also I tried to put the above lines in the rc.local still it "llc" doesnt work. Please tell me what I am doing wrong.
I tried giving
echo $PATH
/usr/local/bin:/usr/bin:/bin:/opt/noob/bin
is the output
But when I give
echo $LD_LIBRARY_PATH
It gives me nothing. I just want to execute this lines on startup. The huddle is I dont want to edit anything in /etc/ directory. PLEASE HELP ME !!
The first snippet shows that you setting the PATH and LD_LIBRARY_PATH environment variables. PATH is used by the shell to binaries, and LD_LIBRARY_PATH to find libraries when you execute a program. None of those commands are linking anything.
$echo PATH will try to deference the echo variable. If that $ is your prompt then it will print "PATH" not the value of the PATH variable.
This is how you echo variables:
echo $PATH
echo $LD_LIBRARY_PATH

Echo $JAVA_HOME returns empty despite being present in .bashrc, .bash_profile, .profile files

I've added the following line in all 3 files:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
If I do, echo $JAVA_HOME, I get empty line as output.
If I do source .bash_profile and then do echo $JAVA_HOME, I get the output correctly.
If I close the terminal application and re-open the terminal app again, echo $JAVA_HOMEshows empty again. Isn't .profile or .bash_profile supposed to load it to bash when I reopen? I added it to all 3 files to be sure. But it just doesn't seem to work
Note: I'm using Zsh on Mac. Does this have anything to do with what I'm facing?
Thanks #JoachimIsaksson for the solution in the comments. I had to move stuff to .zprofile for zshell on Mac and it worked.

Vagrant provision writing PATH variable to .profile

Hi I'm trying to add a directory to the path directly on my vagrant provision but something didn't work as expected. I'm using this line
echo PATH=\""$"PATH:/opt/paraviewopenfoam410/bin\" >> /home/vagrant/.profile
If I use it inside a terminal works as expected adding at the of the .profile the following line
PATH="$PATH:/opt/paraviewopenfoam410/bin"
But when using in vagrant provision the result is:
PATH="PATH:/opt/paraviewopenfoam410/bin"
Missing the $ symbol and breaking the PATH variable
When using the " it will resolve variable so no matter how you put it and escape it, vagrant will resolve the $PATH variable and output the result in your .profile
If you just want to have plain text $PATH you just need to do with '
echo PATH=\'$PATH:/opt/paraviewopenfoam410/bin\' >> /home/vagrant/.profile
will work just fine

What is this $PATH in Linux and how to modify it

I have a few questions on this $PATH in Linux.
I know it tells the shell which directories to search for executable files, so:
What does it mean an environmental variable?
How to change its path? and is it recommended to change it?
IF i change it what are the consequences?
To get your path current $PATH variable type in:
echo $PATH
It tells your shell where to look for binaries.
Yes, you can change it - for example add to the $PATH folder with your custom scripts.
So: if your scripts are in /usr/local/myscripts to execute them you will have to type in a full path to the script: /usr/local/myscripts/myscript.sh
After changing your $PATH variable you can just type in myscript.sh to execute script.
Here is an example of $PATH from RHEL:
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/user/bin
To change your $PATH you have to either edit ~/.profile (or ~/.bash_profile) for user or global $PATH setting in /etc/profile.
One of the consequences of having inaccurate $PATH variables is that shell will not be able to find and execute programs without a full $PATH.
Firstly, you are correct in your statement of what $PATH does. If you were to break it somehow (as per your third point), you will have to manually type in /usr/bin/xyz if you want to run a program in /usr/bin from the terminal. Depending on how individual programs work, this might break some programs that invoke other ones, as they will expect to just be able to run ls or something.
So if you were to play around with $PATH, I would suggest saving it somewhere first. Use the command line instruction
echo $PATH > someRandomFile.txt
to save it in someRandomFile.txt
You can change $PATH using the export command. So
export PATH=someNewPath
HOWEVER, this will completely replace $PATH with someNewPath. Since items in path are separated by a ":", you can add items to it (best not to remove, see above) by executing
export PATH=$PATH:newPath
The fact that it is an environmental variable means that programs can find out its value, ie it is something that is set about the environment that the program is running in. Other environmental variables include things like the current directory and the address of the current proxy.
this is simple and i do like this way.
Open the linux bash shell and print the environment variables:
printenv
I copy "PATH" variable to a text editor and edit as I want. Then update the PATH like this
export PATH= /variable dir list/
It Works.
or if you want to add an single variable use this command.
export PATH = $PATH:/variable_dir_path/
This will extends the PATH with your new directory path.

Creating a command in linux

I have created a simple script:
echo "the path of the current directory is `pwd`"
and saved it by the name pathinfo
then i have created a bin directory at my home page with path as
/home/vpnsadmin/bin
and copied my script(pathinfo) to that bin directory.
Now i want run this script as a command but it is showing error
-bash: /usr/bin/test2: No such file or directory
but if copy my script(pathinfo) to "/usr/bin/" then it runs as a command.
the PATH environment variable is set as-
PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/vpnsadmin/bin
My question is why does the shell not run it as a command when it is present in /home/vpnsadmin/bin.
or else
why does it only check for the binary at /usr/bin and not at /home/vpnsadmin/bin or at /bin
The shell that is to execute your command needs to have the correct PATH variable set at the time of execution and, depending on shell, might need to have created its own internal (hash)map of the available commands.
Assuming you are using bash, try the following with your script saved in /usr/bin:
$ PATH=/ test2
$ PATH=/usr/bin test2
In the first case you should get an expected "not found" error, in the second it should work. The third test to perform is left as an exercise...
And I have to say that the supplied error message looks a bit odd if you actually tried to do
$ test2
and not
$ /usr/bin/test2
before copying the command to /usr/bin.
Edit:
Also, avoid naming your scripts test, in any way shape or form. This causes so much confusion for beginners.
Hint:
man test
Did you have the path to bash at the top of your script and did you use backticks around pwd?
#!/bin/bash
echo "the path of the current directory is `pwd`"
Did you make the file executable?
chmod +x pathinfo
There is another script pathinfo somewhere in your path which contains a call to /usr/bin/test2
Try whereis pathinfo to see how many there are and which pathinfo to see which one your shell currently prefers.

Resources