npm 安装 git linux,如何直接从GitHub安装npm包?

如何直接从GitHub安装npm包?

尝试从github安装模块导致:

package.json上的ENOENT错误。

使用快递轻松复制:

npm install express抛出错误。

npm install express的作品。

为什么我不能从github安装?

这是控制台输出:

npm http GET https://github.com/visionmedia/express.git

npm http 200 https://github.com/visionmedia/express.git

npm ERR! not a package /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/tmp.tgz

npm ERR! Error: ENOENT, open '/home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json'

npm ERR! If you need help, you may report this log at:

npm ERR!

npm ERR! or email it to:

npm ERR!

npm ERR! System Linux 3.8.0-23-generic

npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "https://github.com/visionmedia/express.git"

npm ERR! cwd /home/guym/dev_env/projects_GIT/proj/somename

npm ERR! node -v v0.10.10

npm ERR! npm -v 1.2.25

npm ERR! path /home/guym/tmp/npm-32312/1373176518024-0.6586997057311237/package/package.json

npm ERR! code ENOENT

npm ERR! errno 34

npm ERR!

npm ERR! Additional logging details can be found in:

npm ERR! /home/guym/dev_env/projects_GIT/proj/somename/npm-debug.log

npm ERR! not ok code 0

13个解决方案

861 votes

因为https://github.com/visionmedia/express是网页的URL而不是npm模块。 使用这种味道:

git+https://git@github.com/visionmedia/express.git

如果你需要SSH,还是这种味道:

git+ssh://git@github.com/visionmedia/express.git

Peter Lyons answered 2019-01-15T22:30:29Z

511 votes

您也可以从Github安装npm install

要么

npm install visionmedia/express#branch

还支持直接从Gist,Bitbucket,Gitlab和许多其他专用格式进行安装。 查看npm install文档。

user2487135 answered 2019-01-15T22:31:00Z

111 votes

如果没有安装git,我们可以试试

npm install --save https://github.com/Amitesh/gulp-rev-all/tarball/master

Amitesh answered 2019-01-15T22:31:22Z

45 votes

还有npm install https://github.com/{USER}/{REPO}/tarball/{BRANCH}使用不同的分支。

zakelfassi answered 2019-01-15T22:31:44Z

33 votes

2016年9月更新

从vanilla https github URL安装现在似乎工作:

npm install https://github.com/fergiemcdowall/search-index.git

编辑:有几个用户评论说你不能为所有模块执行此操作,因为您正在从源控制系统中读取,这可能包含无效/未编译/错误的代码。 所以要清楚(虽然它应该不言而喻):鉴于repo中的代码处于npm可用状态,你现在可以非常高兴地直接从github安装

Fergie answered 2019-01-15T22:32:19Z

32 votes

Peter Lyons目前的最佳答案与最近的NPM版本无关。 例如,使用在此答案中受到批评的相同命令现在很好。

$ npm install https://github.com/visionmedia/express

如果您有持续的问题,那么您使用的任何软件包都可能存在问题。

Colin D answered 2019-01-15T22:32:51Z

13 votes

现在在npm的安装文档以及其他许多答案中都很好地介绍了这些方法。

npm install git+ssh://git@github.com:/]

npm install git+ssh://git@github.com:/[#semver:^x.x]

npm install git+https://git@github.com//

npm install git://github.com//

npm install github:/[#]

但是,最近发生变化的值得注意的是npm添加prepare脚本来替换prepublish脚本。 这解决了一个长期存在的问题,即通过git安装的模块没有运行prepare脚本,因此没有完成将模块发布到npm注册表时发生的构建步骤。 见[https://github.com/npm/npm/issues/3055。]

当然,模块作者需要更新他们的package.json以使用新的prepare指令来开始工作。

nextgentech answered 2019-01-15T22:33:27Z

12 votes

直接安装:

npm install visionmedia/express

或者,您可以将"express": "github:visionmedia/express"添加到package.json文件的"dependencies"部分,然后运行:

npm install

Tyler Long answered 2019-01-15T22:33:56Z

12 votes

语法的一般形式是

://[[:]@][:][:][/][# | #semver:]

这意味着你的情况

npm install git+ssh://git@github.com/visionmedia/express.git

来自npmjs文档:

npm安装:

从托管的git提供程序安装程序包,并使用它进行克隆  饭桶。 对于完整的git远程URL,只会尝试该URL。

npm install git+ssh://git@github.com:npm/npm.git#v1.0.27

npm install git+ssh://git@github.com:npm/npm#semver:^5.0

npm install git+https://isaacs@github.com/npm/npm.git

npm install git://github.com/npm/npm.git#v1.0.27

GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/npm.git npm install

| #semver:]是git,git + ssh,git + http之一,   git + https,或git +文件。

如果提供了#,它将用于克隆那个   承诺。 如果commit-ish的格式为#semver:,   可以是任何有效的semver范围或精确版本,npm将寻找   远程存储库中与该范围匹配的任何标记或引用,就像   这将是一个注册表依赖。 如果不是#或

semver:指定,然后使用master。

如果存储库使用子模块,那么这些子模块将是   也克隆了。

如果正在安装的软件包包含一个prepare脚本,那么   将安装依赖项和devDependencies,并进行准备   在打包和安装软件包之前,将运行脚本。

以下git环境变量由npm和will识别   运行git时添加到环境中:

GIT_ASKPASS

GIT_EXEC_PATH

GIT_PROXY_COMMAND

GIT_SSH

GIT_SSH_COMMAND

GIT_SSL_CAINFO GIT_SSL_NO_VERIFY

有关详细信息,请参阅git手册页。

例子:

npm install git+ssh://git@github.com:npm/npm.git#v1.0.27

npm install git+ssh://git@github.com:npm/npm#semver:^5.0

npm install git+https://isaacs@github.com/npm/npm.git

npm install git://github.com/npm/npm.git#v1.0.27

GIT_SSH_COMMAND='ssh -i ~/.ssh/custom_ident' npm install git+ssh://git@github.com:npm/npm.git npm install

ishandutta2007 answered 2019-01-15T22:36:24Z

9 votes

你也可以这样做

npm i alex-cory/fasthacks

要么

npm i github:alex-cory/fasthacks

基本上:

npm i user_or_org/repo_name

Alex Cory answered 2019-01-15T22:36:50Z

8 votes

现在更新您可以:npm install git://github.com/foo/bar.git

或者在package.json:

"dependencies": {

"bar": "git://github.com/foo/bar.git"

}

Sagiv Ofek answered 2019-01-15T22:37:19Z

3 votes

您可以通过npm install命令直接安装github仓库,如下所示:npm install https://github.com/futurechallenger/npm_git_install.git --save

注意:在将由npm命令安装的repo中:

根据@Dan Dascalescu的评论,也许你必须在你的回购中有一个dist文件夹。

你肯定要在repo中有一个package.json! 我忘了添加。

Bruce Lee answered 2019-01-15T22:38:00Z

-4 votes

试试这个命令

npm install github:[Organisation]/[Repository]#[master/BranchName] -g

这个命令对我有用。

npm install github:BlessCSS/bless#3.x -g

Rahil Lakhani answered 2019-01-15T22:38:29Z

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值