我按照以下页面使用NVM安装了NPM:npm throws error without sudo。在Ubuntu终端,一切都很完美。
但是,在IntelliJ终端内部,它表示我没有安装NPM。我试图在语言和框架中设置我的节点解释器>节点和NPM到~/.nvm/versions/node/v6.8.0/bin/node
我启用了Node.js核心库,从那里我可以看到包含npm包。
但终端仍然说我没有安装npm。为什么呢?
这是我的.bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
# Node Environment Setup

答案 0 :(得分:5)
这为我解决了这个问题:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/205964744/comments/205060164
只需编辑您的Intellij启动器/启动脚本,然后将其更改为/bin/bash -i -c <path to ide.sh>
答案 1 :(得分:3)
idea终端默认启动登录shell,因此不会读取我的.bashrc文件。
我通过转到设置来解决问题。然后,展开左侧面板中的“工具”,然后单击“终端”。将-i添加到Shell路径。 (例如/ bin / bash -i)
答案 2 :(得分:3)
ln -s "$(which node)" /usr/local/bin/node
该命令将从您安装的当前节点版本创建符号链接。如果已经有 /usr/local/bin/node 文件,请删除它,因为它可能是一个断开的链接。
答案 3 :(得分:1)
我在Ubuntu运行,并通过不能够从IntelliJ IDEA的终端上运行的节点或能够运行该启动NVM相关的过程的gradle任务中所示的同样的问题。
使用Idea中的终端时,一些现有答案已为我解决,但运行gradle任务仍然无法正常工作。以bash -l -c ...开头(在其他地方也找不到)。
首先解决它通过创建一个启动脚本,做一样东西NVM做,然后做在bash -l -c ...这工作,但发现(后)的-i如上陈述作品以及更简单...所以我的.desktop exec输入行现在是:
JFrame parent = GUI.getInstance().getFrame();
ProgressDialog pDialog = new ProgressDialog(parent,"Working...",false,1);
pDialog.getTextArea().append("Initializing background tasks");
new SwingWorkers.ConnPool(pDialog).execute();
pDialog.setVisible(true);
在这里仅提及它是公认的解决方案,对于在Idea中启动与nvm相关的gradle任务不起作用。
答案 4 :(得分:1)
添加nvm节点解释器对我有用:
设置->语言和框架-> Node.js和NPM->节点解释器
选择~/.nvm/current/bin/node
。如果未在解释器选择中显示,请单击...
并将其添加为新路径。
答案 5 :(得分:0)
如果您以管理员身份运行IntelliJ会有帮助吗?在Windows上,这解决了我设置Node,Bower和Git
时遇到的许多问题答案 6 :(得分:0)
问题是您的环境与运行intellij以及您运行的哪个bash会话nvm <command (install/use)>
不同。通常最好添加nvm建议添加到您的~/.bashrc
中的行,该行将所需的环境变量导出到每个bash会话中。如果您可以从bash运行node --version
并打印v6.8.0,那么您的环境是正确的,您只需要从该上下文运行intellij,我个人不是IDE的粉丝所以我不会这样做。确切地知道,但我想intellij有一种从命令行执行的方法。
答案 7 :(得分:0)
我遇到了同样的问题,并通过指向/usr/local/bin/bash
而不是/bin/bash
来解决了这个问题
答案 8 :(得分:0)
我在Mac OS Catalina中遇到了同样的问题,通过在“偏好设置”->“工具”->“终端”->“应用程序设置”中将Shell路径更新为/ bin / zsh来解决此问题。
答案 9 :(得分:0)