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.
Related
Apologies if this duplicate but a lot of other threads are years old.
I want to update my $PATH variable permanently so it doesn't reset everytime I quit Terminal. I have seen people suggest to run the following:
gedit ~/.bashrc
But this returns:
-bash: gedit: command not found
I have used Spotlight to search my hard disk for the .bashrc file and can't find it. Can anyone help?
Thanks in advance...
You don't need an editor for that, you can do this using bash's output redirection operation.
For example, to add /foo/bar you current PATH, append (>>) to ~/.bashrc:
echo 'export PATH="$PATH":/foo/bar' >> ~/.bashrc
To view the content to STDOUT too, use tee -a:
echo 'export PATH="$PATH":/foo/bar' | tee -a ~/.bashrc
the . before the file means it's hidden so that's probably why it didn't show, just like if you do ls from your home folder you won't see it but ls -la will
to edit your file I would suggest using vi instead if gedit is not available
vi ~/.bashrc
i was trying to add something to my path. But since i'm nog very familiar with the terminal i think i messed something up.
when i do echo $PATH i get:
/Users/christoph/.node/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
but when i open .bashrc i see this:
alias homestead=~/.composer/vendor/bin/homestead
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
export PATH="$PATH:$HOME/.composer/vendor/bin"
And when i open .bash_profile i see this:
export PATH="$HOME/.node/bin:$PATH"
I want to do this step : (to install laravel valet)
Install Valet with Composer via composer global require laravel/valet.
Make sure the ~/.composer/vendor/bin directory is in your system's
"PATH".
And i am very confused on how i should add this path. Also in which file do i need to put it?
I am using MAC OSX El Capitan
Remove this line from your .bashrc!!!
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
It appends a new line to your bashrc each time you log in.
Overall you should modify your PATH env variable only in single file (.bash_profile, but many people will make an error of modifying .bashrc). It works like this: PATH is list of directories splitted by ':' character, $PATH expands to previous value of this list. Example:
export PATH=/fooo:/barr:/bazzz
Places exactly these tree directories in PATH variable. In your case you should have following line in your .bash_profile:
export PATH=$PATH:$HOME/.node/bin:$HOME/.composer/vendor/bin
And remove all unnecessary aliases.
This may be a very noob question, but I'm trying to install Homestead on my Mac. I'm following installation steps via http://laravel.com/docs/4.2/homestead however there is a point in the installation process where it state "Make sure to place the ~/.composer/vendor/bin directory in your PATH so the homestead executable is found when you run the homestead command in your terminal." How do I do this using zsh? Thanks!
in whichever profile you're using (.zprofile or .profile or whatever), you would add the line:
export PATH = ~/.composer/vendor/bin:$PATH
then reload your profile
source ~/.zprofile
If your PATH is in .bashrc file :
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bashrc
If your PATH is in .zshrc file :
echo 'export PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.zshrc
Finally, you should restart your environment
source .bashrc #Bash
source .zshrc #ZSH
Update the file ~/.bashrc like this:
PATH="~/.composer/vendor/bin:{$PATH}"
Setup
Mac OS:
echo 'export PATH=$PATH:$HOME/.composer/vendor/bin' >> ~/.zshrc
Linux:
echo 'export PATH=$PATH:$HOME/.config/composer/vendor/bin' >> ~/.zshrc
To apply restart terminal or:
source ~/.zshrc
To check if it works:
echo $PATH
In one of your start files within home directory (~/.bashrc or ~/.zshrc)
export laravel=/Users/username/.composer/vendor/bin
export PATH="$laravel:$PATH"
$ echo 'export PATH=$PATH:$(composer global config bin-dir --absolute --quiet)' >> ~/.zshrc
TLDR;
A bit more automatic approach to get global vendor/bin path:
$ composer global config bin-dir --absolute
/Users/me/.composer/vendor/bin
In currently open terminal updating PATH will work:
$ PATH=$(composer global config bin-dir --absolute --quiet):$PATH
As it's expected to have global tools always available, we can add it in ~/.zshrc or others, plus:
consider a difference should it be prepended or appended to the PATH,
and use single quotes:
$ echo 'export PATH=$(composer global config bin-dir --absolute --quiet):$PATH' >> ~/.zshrc
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.
My default editor is Pico at my server. I use Bash and Linux.
I tried to change Vim to be my default editor unsuccessfully by:
echo vim > $EDITOR
How can I change Vim to be my default editor?
The following code does not work in file .bashrc:
export EDITOR='vim'
Adding
export EDITOR=vim
to your .bashrc file should really do the trick. (Quotes aren't necessary there and, depending on what quotes you used, they may be the cause for your problem.)
You must open a new shell (or enter source ~/.bashrc at the prompt) after modifying file .bashrc for the modification to take effect.
What is the program from which you want Vim to be started?
I haven't used Git, but the documentation reads:
The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order).
So check whether one of these variables is set:
echo $GIT_EDITOR $VISUAL $EDITOR
git config --get-all core.editor
For me,
export VISUAL=vim
solved the problem.
You can use the Git configuration option core.editor to set the editor of your liking, e.g., nano:
git config [--global] core.editor "nano"
You can also change this by editing the .gitconfig file in your home directory (global) or git repository (create it if it doesn't exist) if you don't have shell access:
...
[user]
name = Your Name
email = your#email.address
[core]
editor = nano
...
Check this command:
sudo update-alternatives --config editor
vim=/usr/bin/vim # Or wherever the Vim binary is
export EDITOR=vim
should do the job.
I don't have an EDITOR environmental variable. My .bashrc file does define this:
alias vi='vim'
And supposedly, if Vim can't find a file called .vimrc in your home directory, it runs in "compatibility mode" and you only get vi features until you say type :nocp.
If it is based on your EDITOR environmental variable, you would set it like this in Bash:
export EDITOR='vim'
Since things have changed in Mac OS X, you will have to add the following in the .profile file in the base directory of the user:
export EDITOR='vim'
You can follow the following instructions:
open the terminal
Type cd (hit Return or Enter (this will take you to the base directory))
Type echo "export EDITOR='vim'" >> .profile (hit Return or Enter and you are done)
(Restart the terminal)
=========================
Or just type:
echo "export EDITOR='vim'" >> ~/.profile
Hit Enter and restart.
If you want vi to be your default history editor (which is why I'm here):
Edit file ~/.bashrc and add
set -o vi
anywhere in the file. Then all the lovely vi command history is available (Esc + K, etc.).
Since none of these answers are helping me:
Here is what the Git documentation are saying, git-commit(1) Manual Page:
The editor used to edit the commit log
message will be chosen from the
GIT_EDITOR environment variable, the
core.editor configuration variable,
the VISUAL environment variable, or
the EDITOR environment variable (in
that order).
Here is the Bash man page excerpt on export (brackets are optional):
export [-fn] [name[=word]]
I had this same challenge when setting up my new MacBook Pro.
Here's how I solved it
To switch to your editor of choice (say nano) on a MacBook you will need to add the following lines to your ~/.zshrc file if your default shell is zsh or ~/.bash_profile if your default shell is bash:
export EDITOR=nano
export VISUAL="$EDITOR"
However, a simpler approach to do this will be to use the echo command to insert them into your ~/.zshrc file if your default shell is zsh:
echo 'export EDITOR=nano' >> ~/.zshrc
echo 'export VISUAL="$EDITOR"' >> ~/.zshrc
OR ~/.bashrc if your default shell is bash:
echo 'export EDITOR=nano' >> ~/.bash_profile
echo 'export VISUAL="$EDITOR"' >> ~/.bash_profile
Run the command below to activate the new configuration:
source ~/.zshrc
Or
source ~/.bash_profile
If you need to switch to other editors of choice you can replace nano with your preferred editor:
Vim - vim
Vi - vi
That's all.