292

I would like to install bootstrap-loader from github in my project using npm

Currently they are maintaining two version of this project which are comaptible with webpack version 1 and 2.

I would like to install version 1. What npm command I should use to install this?

I tried using below one but it is not working.

npm install git://github.com/shakacode/bootstrap-loader.git[#v1] --Save 
Frank T
  • 8,268
  • 8
  • 50
  • 67
Sachin
  • 4,621
  • 6
  • 25
  • 31

10 Answers10

426

There are extra square brackets in the command you tried.

To install the latest version from the brach-name branch, you can use:

npm install "https://github.com/shakacode/bootstrap-loader.git#branch-name" --save
lest
  • 7,780
  • 2
  • 24
  • 22
  • 6
    if we had to attach the specific version. then how would it be along with branch? – Md_Zubair Ahmed Mar 25 '18 at 10:02
  • 2
    @Md_ZubairAhmed The branch name in his example just happened to be named "v1" -- it could be named something else like "my-branch", and behave the same way. – Venryx Oct 23 '19 at 07:18
  • 5
    If you want to install a specific comit, you can do: `npm install https://github.com/username/package#3d0a21cc` Where `3d0a21cc` are the first eight characters of the commit hash. I found this answer [here](https://stackoverflow.com/a/51560215/6086226) – Derk Jan Speelman Feb 13 '20 at 09:33
  • 4
    For info, github has removed the [git:// procotol](https://github.blog/2021-09-01-improving-git-protocol-security-github/#no-more-unauthenticated-git) so you cannot use this method anymore. You should omit the protocol and let npm detect that it is a github repository (see the answer just below : `npm install username/repo#branchName --save`) – Nicolas D Nov 02 '21 at 16:19
124

npm: npm install username/repo#branchName --save

yarn: yarn add username/repo#branchName

e.g. npm i betimer/rtc-attach#master --save (my username is betimer)

// this will appear in your package.json:
"rtc-attach": "github:betimer/rtc-attach#master"

One thing I also want to mention: it's not a good idea to check in the package.json for the build server auto pull the change. Instead, put the npm i (first command) into the build command, and let server just install and replace the package.

One more note, if the package.json private is set to true, may impact sometimes.

Xin
  • 33,823
  • 14
  • 84
  • 85
  • 1
    Any chance you could do this for a package within a monorepo? – Paul Razvan Berg Dec 07 '19 at 18:39
  • @PaulRazvanBerg Yes, you can do `npm install ` – Thilak Rao Jan 29 '20 at 12:52
  • Does not work: npm i facebook/https://github.com/facebook/jest.git#master --save. Or this: npm i facebook/git@github.com:facebook/jest.git#master --save. Does not work either – Daniel Viglione Mar 22 '20 at 17:37
  • @Donato Please follow the pattern in the example – Xin Mar 23 '20 at 02:49
  • @Xin it doesn't work: npm i facebook/jest#master --save ERR! Can't install github:facebook/jest#b5c7092687a265e3f4f2ba6f9787e47e8c6b9d5e: Missing package name – Daniel Viglione Mar 23 '20 at 04:21
  • It works on other packages, which I have just tried. meaning their should be some setting wrong in that package – Xin Mar 23 '20 at 04:52
  • @Xin this is the most popular JavaScript Testing Framework. This is not just a random package. – Daniel Viglione Mar 23 '20 at 13:46
  • 1
    it may be because of package private in package.json or other settings, you can fork that repo, and remove all doubtable settings, then connect to your branch. That's some of my thought. @Donato – Xin Mar 25 '20 at 09:50
44

you can give git pattern as version, yarn and npm are clever enough to resolve from a git repo.

yarn add any-package@user-name/repo-name#branch-name

or for npm

npm install --save any-package@user-name/repo-name#branch-name
mkg
  • 769
  • 7
  • 9
14

Another approach would be to add the following line to package.json dependencies:

"package-name": "user/repo#branch"

For example:

"dependencies": {
    ... other dependencies ...

    "react-native": "facebook/react-native#master"
}

And then do npm install or yarn install

Ilarion Halushka
  • 2,083
  • 18
  • 13
10

I'm using SSH to authenticate my GitHub account and have a couple dependencies in my project installed as follows:

"dependencies": {
  "<dependency name>": "git+ssh://git@github.com/<github username>/<repository name>.git#<release version | branch>"
}
Esteban Borai
  • 2,311
  • 1
  • 21
  • 27
  • 1
    Thanks! Just a comment this is the way I added using npm i. (notice the *:* instead of */* between github.com and the user name) *npm i git+ssh://git@github.com:/.git#* – Sebastian Oscar Lopez Sep 06 '20 at 15:12
5

Had to put the url in quotes for it work

npm install "https://github.com/shakacode/bootstrap-loader.git#v1" --save
user2643679
  • 706
  • 12
  • 18
3

Tried suggested answers, but got it working only with this prefix approach:

npm i github:user/repo.git#version --save -D
Artjom Kurapov
  • 6,115
  • 4
  • 32
  • 42
2

Only solution working for me:

$ npm i https://github.com/{USER}/{REPO}/tarball/{BRANCH} --save

as explained here.

Frugan
  • 319
  • 4
  • 7
-1

Both below versions work for me as of beginning of 2023:

npm i "github:shakacode#bootstrap-loader"

npm i "https://github.com/shakacode/tree/bootstrap-loader/"
mpro
  • 14,302
  • 5
  • 28
  • 43
-7

The Doc of the npm defines that only tag/version can be specified after repo_url.

Here is the Doc: https://docs.npmjs.com/cli/install

menepet
  • 796
  • 13
  • 17