Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run `bun install` in a different directory than the current?

Tags:

bun

For instance, say I'm in the parent folder of app folder where package.json is, and I want to install dependencies for app without cd into it.

I tried:

bun --prefix app install # the npm way
bun --dir app install # the pnpm way
bun --cwd app install # the bun way, but only works with `run` scripts like `bun start`

None of the above worked. Is it supported at all?

like image 689
ZYinMD Avatar asked Oct 12 '25 23:10

ZYinMD


1 Answers

If the directory structure is parent > app > package.json and you are currently in parent, you can install all dependencies with this command:

bun install --cwd ./app

If you need to install a new dependency, for example react, you can use this command:

bun add react --cwd ./app

This command will also create a package.json file if not present.

like image 143
Edoardo Scibona Avatar answered Oct 16 '25 05:10

Edoardo Scibona



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!