在安装新软件包时,npm不会自动添加别名 [英] npm does not add alias automatically when installing a new package

查看:54
本文介绍了在安装新软件包时,npm不会自动添加别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行命令以调用已使用npm安装的软件包时.

When I try to run a command to call a package already installed using npm.

例如:科尔多瓦

cordova -v

cordova -v

它不起作用,仅当我运行完整路径时才起作用:

It does not work, it works only when I run the full path:

/Users/James/.npm-packages/bin/cordova -v

/Users/James/.npm-packages/bin/cordova -v

为此,我需要为每个程序包创建一个别名,以避免使用完整路径进行调用,这会在许多级别上引起许多问题.

For that I need to create an alias for each package in order to avoid calling using the full paths, which causes many issues in many levels.

我的npm版本是:

3.7.3

我的操作系统

Mac OSx El Capitan

Mac OSx El Capitan

推荐答案

/Users/James/.npm-packages/bin/添加到您的 $ PATH :

export PATH="$PATH:$HOME/.npm-packages/bin/"

将以上内容添加到您的〜/.bash_profile 中并提供其来源:

Add the above to your ~/.bash_profile and source it:

source ~/.bash_profile

在打开终端时,AFAIK OSX将bash作为登录外壳运行,因此应使用 .bash_profile 代替 .bashrc .

AFAIK OSX runs bash as a login shell when a terminal is opened, so .bash_profile should be used in favor of .bashrc.

有关更多信息,请参见:什么是PATH?

For more info see: What is PATH?

这篇关于在安装新软件包时,npm不会自动添加别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆