I used a command of the form
echo 'export PATH="..."' >> ~/.zshrc
As a result, the path has been added persistently. Now, I want to remove it. How do I do this? I know that there are posts about this already, but none of the provided solutions worked for my case.
Running echo 'export PATH="..."' >> ~/.zshrc appends the string export PATH="..." to the file ~/.zshrc.
So, to undo this, just edit the file ~/.zshrc and remove the export PATH="..." statement from it.
I'm trying to create an alias for reloading my bash profile.
I added the following line into my ~/.bash_profile
alias src='CMD="source ~/.bash_profile"; echo $CMD;$CMD;'
When I try it(I manually run the command first, so now alias src is defined), it doesn't work:
$ src
source ~/.bash_profile
-bash: ~/.bash_profile: No such file or directory
(Yes, the file is really there) I have similar aliases for other commands they all work. Only this one is causing a problem. Any idea how can I fix this?
This is because there is no file called ~/.bash_profile, or, specifically, a directory called ~/. Bash expands ~ into full path (/home/user/, for example). However, it does not expand after substituting the $CMD variable.
Try using the full path. Or adding this:
FILE="~/.bash_profile" ; eval FILE=$FILE
FILE will have now the full substituted path.
I was trying to add conda into my path. But after I added
export PATH="/data1/neyozhyang/anaconda3/bin/conda"
to my .bash_profile I can not use most of the commands like ls anymore.
It is a linux server.
echo $PATH gives me /data1/neyozhyang/anaconda3/bin/conda
while echo $HOME gives me /data1/neyozhyang
You can choose an editor by it's full path and open ~/.bash_profile.
$ /usr/bin/vim ~/.bash_profile
$ /usr/bin/nano ~/.bash_profile
$ /usr/bin/emacs ~/.bash_profile
And modify the PATH line:
export PATH="/data1/neyozhyang/anaconda3/bin/conda:$PATH"
This might help you get back on your feet (although you don't specify your OS)
PATH=$(/usr/bin/getconf PATH)
That gives you something like /usr/bin:/bin:/usr/sbin:/sbin so you should be able to access the base utilities.
I'm using zsh with oh-my-zsh as my shell and I need to add the Laravel Spark Installer to my path, but I must be missing a step or messing up the syntax
I've added spark-installer to my path like this:
path+=('/Users/retrograde/Development/spark-installer')
Nothing was added to the path, so I edited it directly with:
vim ~/.zshrc
added
# Spark installer
export PATH="$HOME/Users/retrograde/Development/spark-installer:$PATH"
then ran:
source ~/.zshrc
The spark-installer does not show with the other paths upon running echo "$PATH"
Am I missing something? Maybe my syntax is wrong? TIA
I have read several answers on how to set environment variables on OSX permanently.
First, I tried this, How to permanently set $PATH on Linux/Unix but I had an error message saying no such file and directory, so I thought I could try ~/.bash_profile instead of ~/.profile but it did not work.
Second, I found this solution How to set the $PATH as used by applications in os x , which advises to make changes in
~/.MacOSX/environment.plist
but again I had no such file and directory error.
I need a way to set these variables such that it won't require setting them again and again each time I open a new terminal session.
You have to add it to /etc/paths.
Reference (which works for me) : Here
I've found that there are some files that may affect the $PATH variable in macOS (works for me, 10.11 El Capitan), listed below:
As the top voted answer said, vi /etc/paths, which is recommended from my point of view.
Also don't forget the /etc/paths.d directory, which contains files may affect the $PATH variable, set the git and mono-command path in my case. You can ls -l /etc/paths.d to list items and rm /etc/paths.d/path_you_dislike to remove items.
If you're using a "bash" environment (the default Terminal.app, for example), you should check out ~/.bash_profile or ~/.bashrc. There may be not that file yet, but these two files have effects on the $PATH.
If you're using a "zsh" environment (Oh-My-Zsh, for example), you should check out ~./zshrc instead of ~/.bash* thing.
And don't forget to restart all the terminal windows, then echo $PATH. The $PATH string will be PATH_SET_IN_3&4:PATH_SET_IN_1:PATH_SET_IN_2.
Noticed that the first two ways (/etc/paths and /etc/path.d) is in / directory which will affect all the accounts in your computer while the last two ways (~/.bash* or ~/.zsh*) is in ~/ directory (aka, /Users/yourusername/) which will only affect your account settings.
Read more: Mac OS X: Set / Change $PATH Variable - nixCraft
For a new path to be added to PATH environment variable in MacOS just create a new file under /etc/paths.d directory and add write path to be set in the file. Restart the terminal. You can check with echo $PATH at the prompt to confirm if the path was added to the environment variable.
For example: to add a new path /usr/local/sbin to the PATH variable:
cd /etc/paths.d
sudo vi newfile
Add the path to the newfile and save it.
Restart the terminal and type echo $PATH to confirm
You can open any of the following files:
/etc/profile
~/.bash_profile
~/.bash_login (if .bash_profile does not exist)
~/.profile (if .bash_login does not exist)
And add:
export PATH="$PATH:your/new/path/here"
You could also add this
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
to ~/.bash_profile, then create ~/.bashrc where you can just add more paths to PATH. An example with .
export PATH=$PATH:.
If you are using zsh do the following.
Open .zshrc file nano $HOME/.zshrc
You will see the commented $PATH variable here
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/...
Remove the comment symbol(#) and append your new path using a separator(:) like this.
export
PATH=$HOME/bin:/usr/local/bin:/Users/ebin/Documents/Softwares/mongoDB/bin:$PATH
Activate the change source $HOME/.zshrc
You're done !!!
sudo nano /etc/paths
now find the path of command i am giving an example of setting path for flutter.
/Users/username/development/flutter/bin
now cntrol+x and then y . reopen the terminal and check.
launchctl setenv environmentvariablename environmentvariablevalue
or
launchctl setenv environmentvariablename `command that will generate value`
use proper ` and remember to restart application or terminal for the environment variable to take effect.
you can check environment variable by printenv command.
note : environment variable named path is already set by someone else so we are not appending anything to that path at all here.
shows all hidden files like .bash_profile and .zshrc
$ ls -a
Starting with macOS Catalina, mac uses zsh instead of bash. so by default mac uses zsh.
Check which shell running:
$ echo $SHELL
/usr/zsh
$ cd $HOME
$ open -e .zshrc
or if using vim
$ vi .zshrc
Then add it like this
$ export my_var="/path/where/it/exists"
$ export PATH=$PATH:/$my_var/bin
For example: if installed app named: myapp in /Applications
Then
export MYAPP_HOME=/Applications/myapp
export PATH=$PATH:$MYAPP_HOME/bin
or shortcut
export PATH=${PATH}:/Applications/myapp/bin
TADA you set for life !!! Thank me later
19 October 2021.
Confirming iplus26's answer with one correction.
Test environment
OS: macOS 11.6 (Big Sur) x86_64
Shell: zsh 5.8
Below is the order in which the $PATH environment variable is modified:
each line in etc/paths text file gets appended
each line in each text file inside etc/paths.d directory gets appended
finally, the $PATH is further modified in ~/.zshrc
iplus26's answer stated "when (you run) echo $PATH, The $PATH string will be PATH_SET_IN_3&4:PATH_SET_IN_1:PATH_SET_IN_2" but this isn't always the case. It will have to depend on what the script is doing inside .zshrc. E.g. If we do something like
PATH="/new/path:${PATH}"
then, the new path will be in the beginning of the path list. However, if we do something like
PATH="${PATH}:/new/path"
then, the new path will be appended at the end of the path list.
Of course, you'll have to make sure you export the modified path in the ~/.zshrc file.
export PATH=$PATH
One handy command you could use to "pretty print" your path list is
print -l $path
This will print each path on a new line for better readability. Note $path is like $PATH except it's delimited by a single space, instead of a colon, :.
Hopefully this can further clarify for newcomers to this thread.
For setting up path in Mac two methods can be followed.
Creating a file for variable name and paste the path there under
/etc/paths.d and source the file to profile_bashrc.
Export path variable in ~/.profile_bashrc as
export VARIABLE_NAME = $(PATH_VALUE)
AND source the the path. Its simple and stable.
You can set any path variable by Mac terminal or in linux also.