Built-in terminal sessions lose part of $PATH variable

Hello everyone.

I’m having a weird issue with the built-in terminal on OSX. When I load up a terminal, the output says:

npm WARN npm npm does not support Node.js v9.4.0
npm WARN npm You should probably upgrade to a newer version of node as we
npm WARN npm can't make any promises that npm will work with this version.
npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8.
npm WARN npm You can find the latest version at https://nodejs.org/
nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local"
Run `npm config delete prefix` or `nvm use --delete-prefix v9.4.0 --silent` to unset it.

and neither node or npm are available in that terminal. If I run either of the two suggested commands (or if I simply run nvm use 9) I get them back, but only for that terminal session.

Both the default terminal and iTerm (v3.1.5) doesn’t have the same issue.

It looks like it’s a path issue though. With the default terminal, echo $PATH outputs /Users/goffreder/.nvm/versions/node/v9.4.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin after executing all .bash_profile script, but in the built-in terminal it outputs /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin.

This is my current configuration:
phpstorm 2017-3-4 Build #PS-173.4548.32

JRE v1.8.0_152-release-1024-b11 x86_64
node v9.4.0 (npm v5.7.1)
nvm 0.33.8
OSX 10.13.3

Thanks in advance.

0

what shell is configured in Preferences | Tools | Terminal? What do the settings look like? Please attach a screenshot

0
Avatar
Permanently deleted user

This is a screenshot of the terminal output:

And this is what terminal settings are set:

0

will it serve .bash_profile if you add

--login

to shell path in Preferences | Tools | Terminal?

0
Avatar
Permanently deleted user

Yes, but the output is the same. Bear in mind that .bash_profile was served even without `--login`, it just loses part of the $PATH.

This is my .bash_profile content:

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

git_prompt()
{
if ! git rev-parse --git-dir > /dev/null 2>&1; then
echo ""
return 0
fi

git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')

if git diff --quiet 2>/dev/null >&2; then
echo "[$git_branch]"
else
echo "[$git_branch *]"
fi
}

PS1='\u:\W$(git_prompt)\$ '

export NVM_DIR="/Users/emanuele/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi

export EDITOR='nano'
0

Here's a comment I got from a developer on a similar issue.

On Mac OS X things are complicated. An app launched by a GUI launcher (Finder, Dock, Spotlight etc.) receives a pretty empty and useless environment, since standard Unix ways of setting variables via e.g. ~/.profile do not work. What’s more important, there are no sane alternatives.

So, it's not only a PhpStorm problem, it pretty much affects everything running by a GUI launcher.

Workarounds:
1. Start the IDE via Terminal, e.g. open -a /Applications/PhpStorm.app
2. Use /etc/launchd.conf (discussion on Stackoverflow)

2

请先登录再写评论。