GO env variable PATH got messed up - go

I am trying to install package using go with below command:
go install fyne.io/fyne/v2/cmd/fyne#latest
This is the same as what the instruction said but ideally it should return below message
Users/name/go/bin/fyne
But when I enter the command it has below issue
fyne not found
The package author told me You likely don’t have the GOBIN path added to your PATH variable. I suspect it is golang/go#39531 that comes back to bite you.
When I execute export in the command line:
export
I am getting the below Golang path:
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
I thought the path above was messed up because I have done multiple times of installing and uninstalling with uninstalling using below commands
I've done uninstall via:
$ sudo rm -rf /usr/local/go
$ sudo rm /etc/paths.d/go
Althought I've tried to change via:
vim ~/.zshrc
Add a line
export PATH=$PATH:$(go env GOPATH)/bin
It's still not working.
What’s the best approach to resolve adding GOBIN to path?
Thanks!

If all you need is to add GOBIN to PATH, do:
PATH=$PATH:$(go env GOBIN)
Since GOBIN often is ~/go/bin, you usually could get away with just:
PATH=$PATH:~/go/bin
You can add that command to ~/.zshrc to make it persistent and then source it to execute it immediately:
source ~/.zshrc
After that, if your shell remains unable to find fyne, check that current PATH content includes GOBIN with:
echo $PATH
If it doesn't, something went wrong when adding GOBIN to PATH.

Related

zsh: command not found: mv (I'm trying to move composer.phar)

I'm trying to follow a course on Udemy (laravel). I just downloaded XAMPP (I'm on macOS Monterey) and I edited the ~/.zshrc file and added export PATH=/Applications/XAMPP/bin
After that I installed composer which worked successfully, but now when I try to run this command: mv composer.phar /usr/local/bin/composer the shell responds with: zsh: command not found: mv.
Does anyone know how to fix this?
You messed up your PATH. Do a
path+=(/Applications/XAMPP/bin)
instead of the export PATH=... you are using now. And since you want to fiddle with the PATH in your .zshrc, I also suggest to do a
typeset -aU path
near the top of your .zshrc to avoid duplicate PATH entries when you launch an interactive subshell.
The file mv was not found in your PATH, is your PATH variable setup correctly?
Enter echo $PATH to see your PATH variable.
Try /bin/mv to see if the binary file exists.

conda command not found even though path is exported

I installed anaconda3 into my home directory. This is what I am seeing within the terminal:
and my .bash_profile looks like this:
export PATH="/Users/spotter/anaconda3/bin:$PATH"
So I don't understand why conda is not being recognized. When I navigate to anaconda3/bin there is a file called conda in there, but even when I try to call it within that pathway it is still not found.
Spotter, your path to conda is incorrect.
I'm on High Sierra MAC OS and just installed Anaconda3 via HomeBrew command. I had issue with running :
conda
It'd also give me:
-bash: conda: command not found
I tried running:
export PATH=~/anaconda3/bin:$PATH
but it needs ENTIRE path. so here are the correct steps:
$ nano ~/.bash_profile
Now export the ENTIRE path, in my case it was:
export PATH=/usr/local/anaconda3/bin:$PATH
Exit out and run:
$ source ~/.bash_profile
Then try:
$ conda
it'll output:
$ conda --version
conda 4.4.10
I had to type source ~/anaconda3/bin/activate.
For anyone that landed here that is using a non-standard shell (zsh for example) the installer 5.3.1 currently changes the bash_profile not the current active default terminal.
Just open ~/.bash_profile, find the block that is added by the installer and copy it into your .zshrc file (if using zsh)
in Mac OS, for conda >4,4, the conventional way of exporting path (export PATH="Users/myuser/anaconda3/bin:$PATH") is NOT recommended anymore. First, see what is error message in your terminal in Mac when you type conda --version. If it says zsh conda not found then you are using ZSH terminal, so modifying any bash file is useless. In this case, you need to edit your .zprofile. on the other hand, if you get error like bash conda not found you edit .bash_profile. Lets, say we have zsh error, then type in terminal:
sudo nano ~./zprofile
located your conda.sh file by searching in your finder. Most probably it is in
~/anaconda3/etc/profile.d/conda.sh
(for me it was like: /Users/hasbah/opt/anaconda3/etc/profile.d/conda.sh, but instead of anaconda3, it might be conda)
then you type in .zhprfile this:
. /Users/myuser/opt/anaconda3/etc/profile.d/conda.sh
conda activate base
then you save (ctrl+X and Y when was asked to save) and restart the terminal.
Now if you type conda --version you will see it.
so, in short:
sudo nano ~/.zproflie
. /Users/myuser/opt/anaconda3/etc/profile.d/conda.sh
conda activate base
save ./zproflie file
close terminal
open new terminal
conda --version
Rather than adding the ~/anaconda3/bin to your PATH, you should add
. ~/anaconda3/etc/profile.d/conda.sh
conda activate base
to your .bash_profile or .bashrc, or type that in a shell, if you don't want it to be activated for each shell. This is the recommended way to activate conda since conda 4.4. See: https://github.com/conda/conda/blob/master/CHANGELOG.md#440-2017-12-20

Mac OS X: How do I run binaries that are outside usr/local/bin?

I have installed a program that did not automatically put its binaries into usr/local/bin for me. This means that "command not found" errors happen very often whenever I run scripts in that program. I can fix this by copy-pasting the binaries into the usr/local/bin directory, but I don't want to do this every single time, for every single binary. What would be a more efficient way to make the scripts work?
Thank you very much in advance!
Executables are simply resolved via the $PATH variable. It's set to something like
PATH="/bin:/usr/local/bin:..."
(Try $ echo $PATH.)
When you enter a command:
$ foo
each path will be tried in turn and the first matching executable will be executed.
/bin/foo
/usr/local/bin/foo
To execute something outside the default path, simply enter the whole path to the executable:
$ /home/me/bin/foo
$ cd /home/me/bin
$ ./foo
If you find that you need to do that often and want the shortcut, alter your path:
export PATH="$PATH:/home/me/bin"
(Put this in your shell startup script like ~/.profile to automate that.)
Alternatively, symlink the executable to somewhere in your path:
$ ln -s /home/me/bin/foo /usr/local/bin/foo
Add the directory containing the binary to your $PATH environment variable by editing ~/.bash_profile:
export PATH=$PATH:/your/new/path
You can also edit /etc/paths or add a file to /etc/paths.d, but you need to have admin privilege to do that.

mvn command not found in OSX Mavericks

Before marking this as duplicate, I went through these posts, but nothing helped.
'mvn' is not recognized as an internal or external command,
Getting -bash: mvn: command not found,
Can't access mvn command from command line?
Some are specific to windows and did not help. A couple of them on Mac OS X gave suggestions, that I tried but did not help.
What I tried (this is exactly what Maven suggests):
Extract the distribution archive, i.e. apache-maven-3.1.1-bin.tar.gz
to the directory you wish to install Maven 3.1.1. These instructions
assume you chose /usr/local/apache-maven. The subdirectory
apache-maven-3.1.1 will be created from the archive. In a command
terminal, add the M2_HOME environment variable, e.g. export
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1. Add the M2
environment variable, e.g. export M2=$M2_HOME/bin. Optional: Add the
MAVEN_OPTS environment variable to specify JVM properties, e.g. export
MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used
to supply extra options to Maven. Add M2 environment variable to your
path, e.g. export PATH=$M2:$PATH. Make sure that JAVA_HOME is set to
the location of your JDK, e.g. export JAVA_HOME=/usr/java/jdk1.5.0_02
and that $JAVA_HOME/bin is in your PATH environment variable. Run mvn
--version to verify that it is correctly installed.
I see that on the terminal that I used for installation, it works fine. I do not have this issue. but when I tried on a new terminal, I get command not found.
I also added export PATH=$M2 to my .bashrc, I did source and then restarted the terminal, still it did not help.
can someone suggest how to make it available in all sessions of terminal?
Thanks
Try following these if these might help:
Since your installation works on the terminal you installed, all the exports you did, work on the current bash and its child process. but is not spawned to new terminals.
env variables are lost if the session is closed; using .bash_profile, you can make it available in all sessions, since when a bash session starts, it 'runs' its .bashrc and .bash_profile
Now follow these steps and see if it helps:
type env | grep M2_HOME on the terminal that is working. This should give something like
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
typing env | grep JAVA_HOME should give like this:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
Now you have the PATH for M2_HOME and JAVA_HOME.
If you just do ls /usr/local/apache-maven/apache-maven-3.1.1/bin, you will see mvn binary there.
All you have to do now is to point to this location everytime using PATH. since bash searches in all the directory path mentioned in PATH, it will find mvn.
now open .bash_profile, if you dont have one just create one
vi ~/.bash_profile
Add the following:
#set JAVA_HOME
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/usr/local/apache-maven/apache-maven-3.1.1
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
save the file and type source ~/.bash_profile. This steps executes the commands in the .bash_profile file and you are good to go now.
open a new terminal and type mvn that should work.
Solutions above are good but they require ~/.bash_profile. /usr/local/bin is already in the $PATH and it can be confirmed by doing echo $PATH. Download maven and run the following commands -
$ cd ~/Downloads
$ tar xvf apache-maven-3.5.3-bin.tar.gz
$ mv apache-maven-3.5.3 /usr/local/
$ cd /usr/local/bin
$ sudo ln -s ../apache-maven-3.5.3/bin/mvn mvn
$ mvn -version
$ which mvn
Note: The version of apache maven would be the one you will download.
Here is what worked for me.
First of all I checked if M2_HOME variable is set env | grep M2_HOME. I've got nothing.
I knew I had Maven installed in the folder "/usr/local/apache-maven-3.2.2", so executing the following 3 steps solved the problem for me:
Set M2_HOME env variable
M2_HOME=/usr/local/apache-maven-3.2.2
Set M2 env variable
M2=$M2_HOME/bin
Update the PATH
export PATH=$M2:$PATH
As mentioned above you can save that sequence in the .bash_profile file if you want it to be executed automatically.
I got same problem, I tried all above, nothing solved my problem. Luckily, I solved the problem this way:
echo $SHELL
Output
/bin/zsh
OR
/bin/bash
If it showing "bash" in output. You have to add env properties in .bashrc file (.bash_profile i did not tried, you can try) or else
It is showing 'zsh' in output. You have to add env properties in .zshrc file, if not exist already you create one no issue.
The possible solution can be that maven is not installed in your mac system.
Use this command to install maven:
brew install maven
And, to verify, that it is successfully installed, run this command:
mvn -v
If it returns you maven version, then maven is successfully installed in your system.
steps to install maven :
download the maven file from http://maven.apache.org/download.cgi
$tar xvf apache-maven-3.5.4-bin.tar.gz
copy the apache folder to desired place $cp -R apache-maven-3.5.4 /Users/locals
go to apache directory $cd /Users/locals/apache-maven-3.5.4/
create .bash_profile $vim ~/.bash_profile
write these two command :
export M2_HOME=/Users/manisha/apache-maven-3.5.4
export PATH=$PATH:$M2_HOME/bin
7 save and quit the vim :wq!
restart the terminal and type mvn -version
I followed brain storm's instructions and still wasn't getting different results - any new terminal windows would not recognize the mvn command. I don't know why, but breaking out the declarations in smaller chunks .bash_profile worked. As far as I can tell, I'm essentially doing the same thing he did. Here's what looks different in my .bash_profile:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home
export PATH JAVA_HOME
J2=$JAVA_HOME/bin
export PATH J2
M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1
export PATH M2_HOME
M2=$M2_HOME/bin
export PATH M2
You probably have 2 types of shell instances.
sh vs zsh.
Both can have different path defined.
Check your PATH environment variable by typing the below line in terminal
echo $PATH
To test you can change shell mode -
sh to zsh -> type zsh and press enter in terminal (notice $ changes to %)
zsh to sh -> type sh/bash and press enter in terminal (notice % changes to $)
In Both shell modes check for PATH env.
Make both same, or append path from other as needed.
Commands running in 1 shell and not in other would be sorted.
For some of you the cause might be using of other variables in the path to the maven directory. More details in the answer.

Command not found after npm install in zsh

I'm having some problems installing vows via npm in zsh. Here's what I get. I tried installing it with and without the -g option. Do you have any idea what's wrong here?
[❤ ~/Desktop/sauce-node-demo:master] npm install -g vows
npm http GET https://registry.npmjs.org/vows
npm http 304 https://registry.npmjs.org/vows
npm http GET https://registry.npmjs.org/eyes
npm http GET https://registry.npmjs.org/diff
npm http 304 https://registry.npmjs.org/eyes
npm http 304 https://registry.npmjs.org/diff
/usr/local/share/npm/bin/vows -> /usr/local/share/npm/lib/node_modules/vows/bin/vows
vows#0.6.4 /usr/local/share/npm/lib/node_modules/vows
├── eyes#0.1.8
└── diff#1.0.3
[❤ ~/Desktop/sauce-node-demo:master] vows
zsh: command not found: vows
add source /home/YOUUSERNAME/.bash_profile at the beginning of ~/.zshrc
And all missing commands will be detected.
For Mac users : add source /Users/YOUUSERNAME/.bash_profile
If you installed Node.js using Homebrew, npm binaries can be found in /usr/local/share/npm/bin. You should make sure this directory is in your PATH environment variable. So, in your ~/.zshrc file add export PATH=/usr/local/share/npm/bin:$PATH.
If you have added using nvm please add the following to your .zshrc file and restart the terminal since the binaries of the file are not being detected by zsh shell we specify the path
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Mac users only
assuming you installed nvm prior, and npm correctly
(step-by-step guide below on how to install it:
install nvm for Mac users
).
you need to:
Find the '.zshrc' file:
Open Terminal.
Type open ~ to access your home directory.
Press Cmd + Shift + . to show the hidden files in Finder.
Locate the .zshrc.
Edit the '.zshrc' file:
add: source /Users/_user_Name_/.bash_profile to the top of the file (where _user_Name_ stands for your user.
Save the file, and close the Terminal window.
For Mac users:
Alongside the following:
nvm, iterm2, zsh
I found using the .bashrc rather than .profile or .bash_profile caused far less issues.
Simply by adding the latter to my .zshrc file:
source $HOME/.bashrc
On Ubuntu, after installing ZSH, and prevously on the bash terminal installed Node or other packages,
First open:
nano .zshrc
And uncomment the second line:
export PATH=$HOME/bin:/usr/local/bin:$PATH
This works for me, and without writting any line, and I think this option is available on Mac too.
Go to your terminal and run: nano .zshrc
NOTE: If you don't have this file, you may create it using the 'touch' command:
touch ~/.zshrc
Paste the following anywhere below the line containing "export ZSH":
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Now simply hit ^X and you will be asked if you would like to save. Say 'yes' and hit return, then hit return again if it says you are changing a file. You may need to restart your terminal after saving.
Try using node -v as a quick test if you've installed node before.
For me the accepted answer for adding export PATH=/usr/local/share/npm/bin:$PATH to .zshrc didn't work. I tried adding the NVM_DIR as well which solved my issue.
Try vi .bashrc
You will find a line like the following. Copy it.
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
Paste the copied content to .zshrc file
Restart the terminal
I hope this solves your issue.
for macOS users: consider using .profile instead of .bash_profile. You may still need to manually add it to ~/.zshrc:
source $HOME/.profile
Note that there is no such file by default! Quoting slhck https://superuser.com/a/473103:
Anyway, you can simply create the file if it doesn't exist and open it in a text editor.
touch ~/.profile
open -e !$
The added value is that it feels good man to use a single file to set up the environment, regardless of the shell used. Loading a bash config file in zsh felt awkward.
Quoting an accepted answer by Cos https://stackoverflow.com/a/415444/2445063
.profile is simply the login script filename originally used by /bin/sh. bash, being generally backwards-compatible with /bin/sh, will read .profile if one exists
Following Filip Ekberg's research / opinion https://stackoverflow.com/a/415410/2445063
.profile is the equivalent of .bash_profile for the root. I think the name is changed to let other shells (csh, sh, tcsh) use it as well. (you don't need one as a user)
getting back to slhck, a note of attention regarding bash:
(…) once you create a file called ~/.bash_profile, your ~/.profile will not be read anymore.
Another thing to try and the answer for me was to uncomment the first export in ~/.zshrc:
# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH
I solved this by brew upgrade node
For anyone who is still having problem. Don't forget to logout and login again.
In my humble opinion, first, you have to make sure you have any kind of Node version installed. For that type:
nvm ls
And if you don't get any versions it means I was right :) Then you have to type:
nvm install <node_version**>
** the actual version you can find in Node website
Then you will have Node and you will be able to use npm commands
In my case, reinstalling node solved the issue. Anyone can install node via below website:
https://nodejs.org/en/download/
It works for me in zsh. Try nvm install --latest-npm
In my case nvm seemed to have forgotten the global default - maybe some install i did since first adding it.
Simply re-aliasing did the trick:
nvm alias default [insert version number here]
Open a new terminal in order for this to take effect
In my case, i installed node with NVM and after installing z Shell, node and nvm command didn't worked. So what worked for me was installing nvm again with this command :
wget https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
sudo zsh install.sh
Above commands installed nvm again, since node was already installed, it added the node path automatically in .zshrc file and everything worked.
Using Node v12+ on Mac Catalina, global dependencies are showing up in /$HOME/.npm-global/bin
Adding
export PATH="$HOME/.npm-global/bin:$PATH"
To ~/.bash_profile to keep everything in one place, and then adding
source $HOME/.bash_profile
To ~/.zshrc if it's not already there will do the trick. No need to logout and back in, just restart terminal.
Sometimes simple things work. Uninstalling node and installing again worked for me.
brew uninstall node
brew install node
npm update
FOR MAC: I tried some of the above but to no avail, could not get anything to work.
I did have BREW INSTALLED, so although this not be the best approach, with zsh, I did:
sudo chown -R $(whoami) /usr/local/share/man/man8 (for brew access)
brew update && brew install npm (I had had node installed)
npm -v (to confirm install)
nano ~/.zshrc (to empty file changes and save)
This worked for me. Hope this helps someone. #1 bothers me, but I will live with for now.
Just writing this in my terminal fixed the issue. Note that I had to write it separately in my project folder.
export PATH="$HOME/.npm-packages/bin:$PATH"
export PATH="$HOME/.node/bin:$PATH"
Source: https://cloudlinuxtech.com/npm-command-not-found-fix/
I got this message after installing using Homebrew
So I added these lines to the .zshrc and it worked.
export PATH="/usr/local/opt/node#16/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/node#16/lib"
export CPPFLAGS="-I/usr/local/opt/node#16/include"
I think the problem is more about the ZSH completion.
You need to add this line in your .zshrc:
zstyle ':completion:*' rehash true
If you have Oh-my-zsh, a PR has been made, you can integrate it until it is pulled: https://github.com/robbyrussell/oh-my-zsh/issues/3440
I had the same problem while installing Vercel CLI.
In my case, install with sudo.
example: sudo npm i -g vercel
For OSX Catalina users
brew install node#14
I'm using node 14 cause angular won't support latest version (Don't know why)..
Then
echo 'export PATH="/usr/local/opt/node#14/bin:$PATH"' >> ~/.zshrc
Add this at the end of your .zshrc file:
source $HOME/.zshrc.pre-oh-my-zsh
This instantly solved my problem.
In my case this happened after I configured my iterm2 to show git branch names. I basically made my iterm2 to look more elegant. But I noticed my vscode terminal was detecting nvm and npm commands
I have added some lines to .zshrc file when I am configuring iterm2. I had added oh-my-zsh.
But adding the below line to the top of .zshrc file worked for me. If it does not work kill vscode terminal and open it again
Hope this will help someone
export NVM_DIR=~/.nvm
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
For Windows using windows-nvm I had issues after installing an additional version of node. My npm stopped working but only in ZSH. bash, Powershell, and cmd all worked fine. What ended up fixing it was adding an additional alias to zsh of alias npm="npm.cmd" and it started working again. I think it's zsh struggling to find the correct binary, so the .cmd file fixed this issue.
I had node installed with nvm, and the issue i had is that i had 2 versions of node, and i used them with command nvm use v12.xx.0. But somehow they both got detached, and i had to use it again with nvm one of them, and it started to work again how it should.
So the command is(if you have at least one version installed with nvm):
nvm use vxx.xx.0
I had zsh shell and Node installed along with npmrc. I had been using it for years when suddenly it started giving me this error. None of the answers here helped me with this problem.
Turns out I had recently updated my Node version and I had to install npmrc again. So if anyone is having this problem after upgrading their node version, try
npm install -g npmrc

Resources