Add to PATH on server - terminal

i want to add the following directory to my path on the server, and i want it to stay permanently and be allowed to be run from anyplace
this is the directory path:
/usr/local/texlive/2017/bin/x86_64-linux
i tired the following but if i exit the server and login again it is not there and if a website tried to call a function from the directory it can not see it
PATH=/usr/local/texlive/2017/bin/x86_64-linux:$PATH
what is the proper way to add this directory to my default $PATH and make this change permanent

Depends on the shell you are using on the server if bash you could edit your .profile and add something like:
export PATH="/usr/local/texlive/2017/bin/x86_64-linux:$PATH"
If you want it to be for all users you could add it to a file in /etc/profile.d/path.sh.
/etc/profile and /etc/profile.d/*.sh are the global initialization scripts that are equivalent to ~/.profile for each user.
If using zsh add it to ~/.zshrc check this answer https://stackoverflow.com/a/10583324/1135424
If using csh, you could edit the .cshrc something like this:
set path = (/usr/local/texlive/2017/bin/x86_64-linux $path)

Related

Script Shell: How to use a script that I created when I'm not in the directory he is

I created a mv_file.sh script and I want to use it even if I'm not in the path where the script is located.
My question is: What do I have to do to use ./mv_file instead of mv, and this whatever the path I'm in.
You can add the directory, where your script is, to your path. Open ~/.bash_profile (or whatever you choose to use, this sometimes in ~/.bashrc or in ~/.zshrc if you use zsh for example) And add:
PATH=/path/to/script:$PATH
OR you can add the script to a directory that's already in your path. For gnu/linux for example that might be:
$HOME/bin
To see what you're current PATH is:
echo $PATH
If memory serves, this should work just as well on a mac.

How do I see my $PATH on Mac

I've been struggling with "PATH" issues while setting up Rails and other things on Mac for a long time now, and I can't get a straight answer about how I can just see my $PATH and change it. I'm just running the Terminal right now, but if I need to run another program to run Bash commands or something I can probably figure out how to do that.
Execute the following command in Terminal to view the current value of PATH:
echo $PATH
To modify this PATH variable, create a .bash_profile file in your home directory (/Users/username/.bash_profile) and add a line similar to this:
export PATH=$PATH:/new/directory/location
To see your current PATH,
echo $PATH
in a Terminal window.
type:
echo $PATH
You can check your .bash_profile file and edit $PATH variable there. If that file does not exists then you can create a new one and you can export PATH there using:
export PATH=/usr/local/bin:/usr/local/mysql/bin:$PATH

How to add a directory to PATH in the file .bashrc?

After installing python(EPDFee), I want to add the /bin directory to $PATH variable. I am use bash shell. I have found that I have to add the following line in the file .bashrc
export PATH=/home/usrname/epd/bin:$PATH
I have found the file .bashrc, it reads
PATH=$PATH:/opt/bin
# Added by Canopy installer on 2014-03-29
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source /home/an/Enthought/Canopy_64bit/User/bin/activate
Could you please tell me where can I add export PATH=/home/usrname/epd/bin:$PATH to or is should be added in another file?
add the following line to your .bashrc file ...don't forget to replace your path.
export PATH="/path/directory:$PATH"
then do
source .bashrc
to let the changes make effects. I am not sure about other distributions of Linux but It will work on CentOS and RedHat.
You can do it like this :
Define a EPD_HOME var and append it to PATH
EPD_HOME=/home/usrname/epd/bin
PATH=$PATH:$EPD_HOME:$HOME/bin
export PATH
Notice that the $EPD_HOME variable is in the PATH variable and is now loaded once you open a connection to your user on the machine.

How to remove entry from $PATH on mac

I was trying to install Sencha Touch SDK tools 2.0.0 but could not run it properly. It created an entry in the $PATH variable.
Later I deleted the sencha sdk tools folder but didn't realize that the path variable is still there.
When i did echo $PATH I got -
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
I searched on how to remove variables from $PATH and followed these steps :
Gave the command PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
Did echo $PATH which showed /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
gave the command export PATH
Closed terminal and reopened it. Gave the command echo $PATH. This time I got
/Applications/SenchaSDKTools-2.0.0-beta3:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Can anyone tell me what am i doing wrong?
echo $PATH and copy it's value
export PATH=""
export PATH="/path/you/want/to/keep"
Check the following files:
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
Some of these files may not exist, but they're the most likely ones to contain $PATH definitions.
On MAC OS X Leopard and higher
cd /etc/paths.d
There may be a text file in the above directory that contains the path you are trying to remove.
vim textfile //check and see what is in it when you are done looking type :q
//:q just quits, no saves
If its the one you want to remove do this
rm textfile //remove it, delete it
Here is a link to a site that has more info on it, even though it illustrates 'adding' the path. However, you may gain some insight.
What you're doing is valid for the current session (limited to the terminal that you're working in). You need to persist those changes. Consider adding commands in steps 1-3 above to your ${HOME}/.bashrc.
If you're removing the path for Python 3 specifically, I found it in ~/.zprofile and ~/.zshrc.
$PATH contains data that is referenced from actual files. Ergo, you should find the file containing the reference you want to delete, and then delete said reference.
Here is a good list to run through progressively [copied from #Ansgar's answer with minor updates].
/etc/bashrc
/etc/profile
~/.bashrc
~/.bash_profile
~/.profile
~/.MacOSX/environment.plist
/etc/paths
/etc/paths.d/
Note that /etc/paths.d/ is a directory that contains files with path references. For example, inside this directory may be a file called, say, fancy-app, and inside this file you'll see an entry like below:
/path/to/fancy-app
This path will appear in your $PATH and you can delete the entry in the file to remove it, or you can delete the file if it has only the one reference you want to remove.
Use sudo pico /etc/paths inside the terminal window and change the entries to the one you want to remove, then open a new terminal session.
when you login, or start a bash shell, environment variables are loaded/configured according to .bashrc, or .bash_profile. Whatever export you are doing, it's valid only for current session. so export PATH=/Applications/SenchaSDKTools-2.0.0-beta3:$PATH this command is getting executed each time you are opening a shell, you can override it, but again that's for the current session only. edit the .bashrc file to suite your need. If it's saying permission denied, perhaps the file is write-protected, a link to some other file (many organisations keep a master .bashrc file and gives each user a link of it to their home dir, you can copy the file instead of link and the start adding content to it)
Close the terminal(End the current session). Open it again.
If the manual export $PATH method does not seem to be working after you close the terminal and open again, definitely check the shell configuration files.
I found a small script that kept adding some more path in front of the $PATH everytime it was open.
For zsh you can check the ~/.zshrc file.

How to make a shell script global?

I am on Mac's OS 10.6, and I am trying to learn a thing or two about shell scripting. I understand how to save a shell script and make it executable, but I am wondering what I can do or where I can save the file to make it global (that is, accessible no matter what folder I am in).
For example, if I save a .sh file in the /Users/username/ directory and make it executable, I can only execute that script in that specific directory. If I navigate to /Users/username/Downloads, for example, I can't execute the script.
Also, any suggestions of resources for learning more about shell scripting would be helpful. Thanks
/usr/local/bin would be the most appropriate location. Mac OS X has it in the PATH by default
There are two ways to do it -
Put your script in usr/local/bin and make sure it is executable(chmod +x my_script)(This is already set in the path, you can check by doing an echo $PATH)
Create a folder in your home directory called bin. (For your personal scripts)
cd ~ (Takes you to your home directory)
mkdir bin (create a bin folder)
vim .bash_profile (to set path environment variable)
export PATH=~/bin:$PATH (Press i then add this line and then do esc and type :wq)
Now you can just type the name of your script and run it from anywhere you want.
** NOTE: If you want to run the script with a shortened command rather than typing your entire filename, add the following to your .bash_profile:
alias myscript='my_script.sh'
Then you can run the script by simply typing myscript. (you can sub in whatever alias you'd like)
Traditionally, such scripts either go in ~/bin (ie: the bin directory in your home directory) or /usr/local/bin/ The former means the script will only work for you, the latter is for scripts you want anybody on the system to be able to run.
If you put it in ~/bin, you may need to add that to your PATH environment variable. /usr/local/bin should already be on the path.
In mac operating system
Open bash ~/.bashrc file.
add path of your script in your bashrc file , using
export PATH="$PATH:/Users/sher.mohammad/Office/practice/practiceShell"
Open your ~./bash_profile file and add [[ -s ~/.bashrc ]] && source ~/.bashrc
open new terminal window
Now whenever you will open your terminal your script will be loaded
This one is super easy if you are familiar with your bashrc file! This will entirely use just your .bashrc file and takes 2 seconds to accomplish.
(I use Arch Linux Manjaro so I use .bashrc located in my home directory)
The code to be placed in your .bashrc file:
# Simple bashrc method to launch anything in terminal from any directory
YOURCOMMAND () {
cd /path/to/directory/containing/your/script/ && ./YOURSCRIPT
}
As you can see, first you use the simple 'cd' command and give it the directory of the scripts location, then use '&&' so that you can make the next command executed right after, and finally open your script just as you would normally! Super easy and saved right in your .bash file! :)
Hope I've helped someone!
Sincerely,
AnonymousX
On using bash shell, write that script as function and then put it to the .bashrc or source the file which containing that function by "source file_name"
Now execute the script by function call in the shell.
Either saving it in /usr/bin (or any other directory present in PATH) or editing PATH to include the directory you saved it in will basically make it run in any directory.
from the working directory of 'script.sh'" mv [script.sh] /usr/local/bin"( not tested but seems to be the least complex way IMO.)
You should put it in the global executable directory on your machine. I think that would usually be /usr/bin on Unix-based operating systems (this would however most often require super user privileges on that machine).
You could also put it in any other directory that is in the $PATH environment variable, although it would only work for those users who have that directory in that variable.
You can find the value of $PATH by typing echo $PATH in a shell. The directories are separated by :.

Resources