PATH error: "not a valid identifier" - bash

I had to get a new hard drive on my Mac and in setting up my developer environment, I'm getting this error/message in the terminal (iTerm2):
-bash: unset: `PATH=/usr/local/opt/icu4c/bin:/usr/local/share/npm/bin:/Users/(mycomputername)/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/(mycomputername)/bin': not a valid identifier
From what I've been able to research myself so far, it might be related to installing node using brew. (I could be wrong.)
FYI:
which ruby
/usr/bin/ruby
which node
/usr/local/bin/node
which python
/usr/local/bin/python
Also, I'm using these instructions to set up. I'm aware a few things in this list are out of date:
https://github.com/nicolashery/mac-dev-setup
EDIT:
Contents of ~/.bash_profile:
# Add Homebrew /usr/local/bin and User ~/bin to the $PATH
PATH=/usr/local/bin:$PATH PATH=$HOME/bin:$PATH
export PATH
# Load the shell dotfiles, and then some: # * ~/.path can be used to extend $PATH.
# * ~/.extra can be used for other settings you don’t want to commit.
for file in ~/.{path,bash_prompt,exports,aliases,functions,extra};
do [ -r "$file" ] && source "$file"
done
unset fileexport PATH="/usr/local/opt/icu4c/bin:$PATH"
export PATH="/usr/local/opt/icu4c/sbin:$PATH"

The issue is this line in your ~/.bash_profile:
unset fileexport PATH="/usr/local/opt/icu4c/bin:$PATH"
comment it out with # and restart iTerm2

Related

Terminal (zsh) command not found for global npm installs

This is driving me nuts! I did a lot of googling and tried various things. (I do not consider this to be a superuser topic)
I'm having a lot of troubles with terminal lately. I must have messed up somewhere, because it used to work just fine and now I can't get it to recognize my commands anymore neither nvm or global npm packages like expo. It just gives me errors like this:
▶ expo
zsh: command not found: expo
▶ nvm ls
zsh: command not found: nvm
(BTW: npm, brew and j commands are found 🤔)
If I do echo $PATH I get:
/Users/norfeldt/Library/Android/sdk/tools/bin:/Users/norfeldt/Library/Android/sdk/tools:/Users/norfeldt/Library/Android/sdk/platform-tools:/Applications/anaconda/bin:~/Library/Python/2.7/bin:~/.npm-global/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
(strange behavior is that if I do echo $PATH again it returns two times the same output in one line)
A readable version of it (replacing : with :\n
/Users/norfeldt/Library/Android/sdk/tools/bin:
/Users/norfeldt/Library/Android/sdk/tools:
/Users/norfeldt/Library/Android/sdk/platform-tools:
/Applications/anaconda/bin:
~/Library/Python/2.7/bin:
~/.npm-global/bin:
/usr/local/bin:
/usr/bin:
/bin:
/usr/sbin:
/sbin
My .zshrc file looks like this:
# Node & NPM
#PATH="/usr/local/bin:$PATH"
PATH="~/.npm-global/bin:$PATH"
#PATH="~/.npm-global/lib/node_modules:$PATH"
# Git
alias master="git checkout master"
alias dev="git checkout develop"
alias hotfix="git flow hotfix"
alias feature="git flow feature"
alias tags="git push --tags"
# Pip - https://gist.github.com/haircut/14705555d58432a5f01f9188006a04ed
PATH="~/Library/Python/2.7/bin:$PATH"
# added by Anaconda2 4.4.0 installer
PATH="/Applications/anaconda/bin:$PATH"
# Android
export ANDROID_HOME=/Users/norfeldt/Library/Android/sdk
PATH="${ANDROID_HOME}/platform-tools:$PATH"
PATH="${ANDROID_HOME}/tools:$PATH"
PATH="${ANDROID_HOME}/tools/bin:$PATH"
alias emu="pushd ${ANDROID_HOME}/tools;emulator -avd Pixel_2; popd"
# Path to your oh-my-zsh installation.
export ZSH=/Users/norfeldt/.oh-my-zsh
ZSH_THEME="avit"
# Autojump
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
# shell startup.
plugins=(git)
source $ZSH/oh-my-zsh.sh
# Load zsh-autosuggestions.
source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# zsh-syntax-highlighting
source /Users/norfeldt/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
export PATH
ANY help would be HIGHLY appreciated!
UPDATE
Reading the kind answer from #l'L'l and this answer I did the following:
Updated my .bash_profile to
export NVM_DIR=~/.nvm
source ~/.nvm/nvm.sh
(it's the only thing in that file)
created a .bashrc by $touch .bashrc (Might have deleted the old one.. But this is just an empty file..)
Added the following lines to .zshrc
PATH="$PATH:$HOME/.npm-global/bin/" # Changed ~ to $HOME
PATH="$PATH:$HOME/.npm-global/lib/node_modules" # Changed ~ to $HOME
...
# Bash stuff
source ~/.bashrc
source ~/.bash_profile
Did a source ~/.zshrc and restarted my terminal.
NOW the nvm AND expo works! THANKS
There are a few things you might try, the first would be to source ~/.bash_profile from your .zshrc file. It's possible the nvm command was setup there and your zsh shell simply doesn't know it exists.
Note: On OS X, if you get nvm: command not found after running the
install script, one of the following might be the reason:-
your system may not have a .bash_profile file where the command is
set up. Simply create one with touch ~/.bash_profile and run the
install script again you might need to restart your terminal instance.
Try opening a new tab/window in your terminal and retry. If the above
doesn't fix the problem, open your .bash_profile and add
the following line of code:
source ~/.bashrc
For more information about this issue and possible workarounds, please
refer here
↑ Since you are using zsh instead at source ~/.bash_profile & ~/.bashrc in .zshrc.
If you used homebrew to install, then you might want to add the following into .zshrc:
export/source nvm installed with homebrew:
# source nvm
export NVM_DIR=~/.nvm
if hash brew 2>/dev/null; then
source $(brew --prefix nvm)/nvm.sh
source `brew --prefix`/etc/profile.d/z.sh
fi
npm not installed via homebrew:
export NVM_DIR="~/.nvm"
source ~/.nvm/nvm.sh
[[ -s "$NVM_DIR/nvm.sh" ]] && \. "$NVM_DIR/nvm.sh" # load nvm
[[ -s "$NVM_DIR/bash_completion" ]] && \. "$NVM_DIR/bash_completion" # load nvm bash_completion
↳ https://github.com/nvm-sh/nvm
I have no OSX to try... but the paths for zsh might belong into there:
/etc/paths, /private/etc/paths or into /private/etc/paths.d
Beside that, there's an auto-complete plugin for npm.

$PATH error every time Terminal is Opened

I had installed Postgres.app before and after I uninstalled via App Cleaner now every time I open terminal this error appears in the first line I should mention that a followed what documentation for uninstalling the Postgres on their website but it doesn't work for me.
Warning: $PATH entry "/Applications/Postgres.app/Contents/Versions/9.6/bin" is not valid (No such file or directory)
.bash_profile:
# source ~/.profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
export PATH="/usr/local/opt/node#6/bin:$PATH"
how can I get rid of this annoying warning?
Thanks.
You should look at all bash initialization files. There may be many, depending on your distro. There's a good list on tldp:
/etc/bash.bashrc
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
Consider that some of these files may also include all files in some directory. For example on most instances /etc/profile will run every .sh file in /etc/profile.d/, this may include a paths file called /etc/profile.d/extrapaths.sh.
EDIT:
After checking the documentation for PostgresApp (1, 2), and this issue I found that it uses a file called /etc/paths.d/postgresapp. Be sure to check it.
If you'd like to remove the paths, it states that you should run the following command:
sudo rm /etc/paths.d/postgresapp

How do I add directories to PATH?

Long story made short, I am trying to issue myself an SSL certificate using LetsEncrypt, and have recently installed rbenv to make this process easier. After installing rbenv, I check to see if everything checks out using
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
I than get this message saying that there are no versions of ruby installed. After trying to install ruby using the command
"rbenv install 2.3.1"
I get this error
rbenv: no such command `install'
Is it because the path to my rbenv shims aren't in my PATH variable ? If this is the case how do I add directories to my PATH variable ? I know you have to add them to your bash_profile file, but am not sure where in this file I need to add something, and what I need to add.
~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
function letsencrypt_webfaction {
PATH=$PATH:$GEM_HOME/bin GEM_HOME=$HOME/.letsencrypt_webfaction/gems RUBYLIB=$GEM_HOME/lib ruby2.2 $HOME/.letsencrypt_webfaction/gems/bin/letsencrypt_webfaction $*
}
eval "$(rbenv init -)"
PATH=$PATH:$HOME/bin
export PATH
export PATH="$HOME/.rbenv/bin:$PATH"
Always be careful when editing the profile.
Better make a backup first
switch to home directory:
cd
list hiden files:
ls -la .bash*
make a backup copy of .bash_profile:
cp -p .bash_profile .bash_profile.bak
check the current PATH: echo $PATH
check if ruby is in the PATH: which ruby
check the ruby version: ruby --version
I am not sure where this function is comming from in your .bash_profile: function letsencrypt_webfaction()
Use : as a separator and add a new directory new_dir to your PATH, use $PATH to keep the contents of the actual PATH, then export the new PATH:
PATH=$PATH:/new_dir:/new_lib
export PATH
Verify if the PATH is what you need from the terminal: echo $PATH
Personaly I sugest making a backup of .bash_profile as it is. Comment out with # the 3 lines for the function and the others where the PATH appears and add this:
export RUBYLIB=$HOME/lib
export GEM_HOME=$HOME/gems
export PATH=$HOME/bin:$PATH:
After this please check the bulet points above and see if you have the ruby version you expect.
According to the documentation you should install the ruby-build plugin:
The rbenv install command doesn't ship with rbenv out of the box,
but is provided by the ruby-build project.

-bash: vim: command not found

I have been trying to install something in my bash_profile, which looked like this:
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
I was trying to add the Path to my pg_config file: /Applications/Postgres.app/Contents/Versions/9.6/bin
So my bash_profile looked like:
# Set architecture flags
export ARCHFLAGS="-arch x86_64"
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
When I tried to source the file i got:
-bash: /usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:: No such file or directory
When I try to open the bash_profile I now get:
-bash: vim: command not found
What have I done wrong?
Additional info
I have installed Python, PGAdmin4 and Django via Homebrew
I have downloaded Postgress.app also and was trying to install psycopg2, when it told me I had no pg_config. So I was trying to add the path to my bash_profile. Which I think is the right thing to do
#melpomene and #Jdamian I think were right here. I had trouble trying to then find and open my bash_profile as I couldn't use the terminal to run:
defaults write com.apple.finder AppleShowAllFiles YES
Thankfully this answer helped though: https://apple.stackexchange.com/a/186378/70982
I navigated in finder to my ~/ folder and and ran
⌘ CMD+⇧ SHIFT+.
Opened in sublime and My path had was written as this:
export PATH=/usr/local/bin:/Applications/Postgres.app/Contents/Versions/9.6/bin:
$PATH
So I removed the carriage return so it all fits on one line and that seemed to help. I can now open Vim

How to change path for homebrew: "config" scripts exist outside your system or Homebrew directories

Goal: install Ruby 2.0.0
Brew Doctor says:
Warning: "config" scripts exist outside your system or Homebrew directories. `./configure`
scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/opt/sm/pkg/active/bin/curl-config
/opt/sm/pkg/active/bin/ncurses5-config
/opt/sm/pkg/active/bin/ncursesw5-config
/opt/sm/pkg/active/bin/pkg-config
/opt/sm/pkg/active/bin/xml2-config
/opt/sm/pkg/active/bin/xslt-config
I found the answer here: Brew doctor gives out warnings but don't know how because he didn't tell us how to do it
I need to remove /opt/sm/pkg/active/bin/ from my path.
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin:/Development/android-sdk-macosx/platform-tools:/Development/android-sdk-macosx/tools
but when I open my file
touch ~/.bash_profile; open ~/.bash_profile
I get:
export PATH=${PATH}:/Development/android-sdk-macosx/platform-tools:/Development/android-sdk-macosx/tools
##
# Your previous /Users/john/.bash_profile file was backed up as /Users/john/.bash_profile.macports-saved_2013-06-06_at_14:30:25
##
# MacPorts Installer addition on 2013-06-06_at_14:30:25: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
Notice the path I'm trying to remove is not in the file, but it's in my path. What do I do??
The /opt/sm is in the /etc/profile.d directory. Open it by entering
cd /etc/profile.d
in terminal and then
open .
Open sm.sh file in text editor and then
change
PATH="${PATH}:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin"
to
#PATH="${PATH}:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin"
and then quit and relaunch Terminal. Run brew doctor 'Warning' should be gone.
It seems that "sm" comes from RailsInstaller, at least in my case. Following the approach in this post, I commented out the line in /etc/profile.d/sm.sh and restarted Terminal. This solved the above brew doctor errors.

Resources