How to change where pnpm installs the global packages? - pnpm

Question is simple, I want to change where pnpm installs the global packages.
I have a custom Node installation on Windows and would prefer to have everything under that directory, especially as that directory is in my PATH but not the default one.
And to make it clearer I don't want to set the store dir, that's already configured and it's being created at the right place, now I would like to have the executable (*.cmd, *.ps1) and the pnpm-globals stuff in my custom dir as well.
npm already installs by default on the same directory node is located but pnpm forces on the default Roaming folder and setting prefix in etc/npmrc makes no change.

For pnpm v6, use global-dir instead of pnpm-prefix:
pnpm config set global-dir <dir>
Although <dir> can be arbitrary, to keep the original directory structure, it should be <your npm prefix>/pnpm-global.
From changelog:
The pnpm-prefix setting is removed. Use global-dir to specify a custom location for the globally installed packages.

Set the pnpm-prefix config with the desired location
pnpm config set pnpm-prefix <dir>

Related

Why pnpm has two stores when using with nvm?

I did found pnpm is using two stores when installed in nvm environment.
/Users/me/.pnpm-global/1
/Users/me/.nvm/versions/node/v10.15.3/pnpm-global/1
Trying to understand, why it is so.
~/.pnpm-global is not the store. It is the location where the global packages are installed. For instance, when you run pnpm i -g webpack-cli, webpack will be installed into ~/.pnpm-global.
It is probably some bug that you have two of those. There should be one global folder, probably this one only: /Users/me/.nvm/versions/node/v10.15.3/pnpm-global/1
The global store is located at ~/.pnpm-store

Remove existing Go installation before updating?

I am using windows 10.
In this link is it been asked to remove current Go installation before updating to new version. The current installation folder is something like: C:\Go . And it is been asked to remove this folder first before installing the latest version.
But I already have my projects under C:\Go\src. So I can't afford to delete it just like that. Not sure what I am missing. I have never updated Go before, so this is new to me. Thanks.
Those same instructions tell you to...
Create your workspace directory, %USERPROFILE%\go. (If you'd like to use a different directory, you will need to set the GOPATH environment variable.)
C:> cd %USERPROFILE%\go\src\hello
C:\Users\Gopher\go\src\hello> go build
So your src directory should not be in C:\Go\src but %USERPROFILE%\go\src\ (that is in your home directory). If you've been using C:\Go\src, move it to %USERPROFILE%\go\src\ and use that going forward.

Script name collision in terminal

I just installed
npm install -g angular-cli
And attempted to initialize a new project
ng new foo
Unfortunately I already have nailgun installed which also uses the ng keyword.
How can I set which has precedence? Better yet, is there an easy way to rename one of them?
The first one found in the path is the one that will be called, so you could re-order your path as a first option. When you needed nailgun, you could swap the order for the nailgun and global npm modules directories in your path.
You could rename ng in the .bin directory in your global install location, but this could have side effects if other angular tools expect to be able to call ng.

PHPUnit - How to add vendor/bin into path?

I installed PHPUnit with composer. Everytime I run it, I have to call vendor/bin/phpunit. How can I put vendor/bin into path, so that next time I only need to call phpunit to run it?
You could add the current directory into your path.
For Linux/Mac add the following into your .bash_profile, Windows would be similar, alter the line below and add it into your PATH.
# include the current `vendor/bin` folder (Notice the `.` - This means current directory)
PATH="./vendor/bin:$PATH"
Remember to restart your terminal or resource your bash_profile.
Now you should be able to run: phpunit and it will automatically look for it within ./vendor/bin and if it exists it will execute using that.
If you are running on Homestead (or some other Linux/Ubuntu system):
alias p='vendor/bin/phpunit'
Then you can just type p and it will run your tests
If you are using Homestead - you can add this alias to your aliases file so it is always there.
Another easy solution, from the composer documentation, is to set your bin-dir setting to ./. This will install the binary in your root directory.
"config": {
"bin-dir": "./"
}
Then you can just run ./phpunit. I typically set bin-dir to bin, then type bin/phpunit. It's short enough for me.
If you already have phpunit installed, you will need to delete the vendor/phpunit directory and rerun composer install before composer will move the binary.

Installing packages in a local directory

What is the best practice to install packages (those with go get...) in a local directory?
Example: I'd like to try out the Revel web framework, but I don't want to clutter my go installation at /usr/local/go.
Normally I'd say sudo go get github.com/robfig/revel as written on the home page, but that would install it beneath /usr/local/go/src/pkg/....
Is there an easy way to say (for example) go get --local ... and have the package in the current (sub) directory?
To expand on keks answer, you can update your .bashrc to look like this
export GOROOT=/usr/local/go
export GOPATH=~/workspace/me/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
Now all packages installed with go get are separate from the go distribution.
You can export the env variable GOPATH. For me it is ~/local/lib/go. This folder has the subfolders bin, pkg and src, so it's just like /usr/local/go. The go-tool will then automatically download , build and install packages into this directory.
You might want to consider using Go Version Manager (gvm).
Apart from switching between Go versions easily, it also lets you switch between pkgsets ("workspaces").
First you create a set
gvm pkgset create myproject
and then you use it
gvm pkgset use myproject
Works like a charm.

Resources