mirror of
				https://github.com/emrusz/emrusz.git
				synced 2025-10-30 21:19:57 -04:00 
			
		
		
		
	Add npm article
This commit is contained in:
		
							parent
							
								
									80205b6316
								
							
						
					
					
						commit
						c202607446
					
				
					 1 changed files with 47 additions and 0 deletions
				
			
		
							
								
								
									
										47
									
								
								_posts/2025-03-17-node.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								_posts/2025-03-17-node.md
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,47 @@ | |||
| --- | ||||
| title: "NPM Global Without Sudo" | ||||
| categories: | ||||
|   - programming | ||||
| tags: | ||||
|   - nodejs | ||||
|   - npm | ||||
|   - linux | ||||
|   - security | ||||
| --- | ||||
| 
 | ||||
| ## Don't Use `sudo` With `npm` | ||||
| 
 | ||||
| I have seen quite a few programmers install global packages on their machine with `sudo npm`. Generally, that isn't a great idea. I was inspired by Andrew Crites's article "[Don’t Use `sudo` with `npm` …still](https://www.grammarly.com/blog/punctuation-capitalization/italics/)" to post this quick guide on configuring npm prefixes. | ||||
| 
 | ||||
| Why shouldn't you use `sudo` with `npm`? Go read the Crites's article! | ||||
| 
 | ||||
| ### Creating a `npm` Prefix | ||||
| 
 | ||||
| Set a prefix in your npm configuration using the `npm config` command. | ||||
| 
 | ||||
| ```bash | ||||
| npm config set prefix './local/' | ||||
| ``` | ||||
| 
 | ||||
| This modifies your `~/.npmrc` to include the following line. | ||||
| 
 | ||||
| ```bash | ||||
| prefix=~/.local/ | ||||
| ``` | ||||
| 
 | ||||
| ### Updating `$PATH` | ||||
| 
 | ||||
| If you intend to run globally installed packages from the command line you must add the new prefix location to your `$PATH`. Replace `~/.zshrc` with the appropriate configuration file for your shell e.g. `~/.bashrc`. | ||||
| 
 | ||||
| ```bash | ||||
| mkdir -p ~/.local/bin | ||||
| echo 'export PATH="$HOME/.local/bin/:$PATH"' >> ~/.zshrc | ||||
| ``` | ||||
| 
 | ||||
| ### Installing Global Packages | ||||
| 
 | ||||
| You can now install global packages in the scope of your user _without_ `sudo`! | ||||
| 
 | ||||
| ```bash | ||||
| npm i -g packagename | ||||
| ``` | ||||
		Loading…
	
	Add table
		
		Reference in a new issue