Giovani Harada

How to Use 'bun' (Linux Package Manager) on PowerShell Core

Exploring 'bun' as a replacement for npm on a personal project is enticing. However, when using Windows 11 as your primary operating system, the Windows version of 'bun' might lack certain features.

Primarily, leveraging WSL (Windows Subsystem for Linux) to run 'bun' seems logical. Yet, if PowerShell is your preferred terminal on Windows, here's a solution that allows 'bun' to function within your PowerShell environment:

Instructions:

  1. If not done already, enable WSL and install a Linux distribution from the Microsoft Store (such as Ubuntu).

  2. In your WSL terminal, install 'bun' using the bash script available at https://bun.sh/package-manager.

  3. Within your WSL terminal, edit the file ~/.bashrc using any text editor. Comment out the lines containing export BUN_INSTALL="$HOME/.bun" and export PATH=$BUN_INSTALL/bin:$PATH by adding a # at the beginning of each line.

  4. Copy the contents from the 'bun' folder .bun/bin/ to /usr/bin/ using a command like:
    sudo cp .bun/bin/bun /usr/bin/bun
    sudo cp .bun/bin/bunx /usr/bin/bunx

  5. In PowerShell, execute Install-Module WslInterop.

  6. Edit your PowerShell profile and add Import-WslCommand "bun".

After completing these steps, reopen your PowerShell, and 'bun' should be available as if it were installed directly on your Windows environment.