4

I have ran the installation script by pasting this code:

$ curl https://bun.sh/install | bash

However, when I try to get the version of bun, it says it could not find it:

$ bun --version

Command 'bun' not found, did you mean:

  command 'ben' from deb ben (0.9.0ubuntu2)
  command 'bus' from deb atm-tools (1:2.5.1-4)
  command 'zun' from deb python3-zunclient (4.0.0-0ubuntu1)

Try: sudo apt install <deb name>
sno2
  • 3,274
  • 11
  • 37
  • This problem has nothing to do with bun. – Kevin B Jul 07 '22 at 18:40
  • This is a Bun installation script and we have answered this question 3 times in the Bun discord. People are assuming that the installation script would add Bun to path similar to what Deno does. This will help stop us from feeling like broken record players and waste time @KevinB – sno2 Jul 07 '22 at 18:53
  • You can also see https://stackoverflow.com/a/60217812/10873797 for precedence – sno2 Jul 07 '22 at 19:05

7 Answers7

4

I had the same issue running on Windows 10 WSL2 Ubuntu-22.04 with Bun v0.1.5.

The solution (and more detail just in case anyone needs it) below:

The executable for bun is in the directory "/home/username/.bun". You need to add this to your $PATH so that this can be found when typing bun commands such as "bun --help".

The bun setup process does not add this path so you need to do it yourself.

Two ways to do this :

(1) Manual method

Type in the terminal:

export BUN_INSTALL="/home/YOUR_USERNAME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"

Replacing YOUR_USERNAME with your real username (the current username can be found by typing 'whoami' in the terminal).

Note: This process will have to be REPEATED for every new shell you open.

(2) Automatic method

Edit the .bashrc file :

nano ~/.bashrc 

at the end of this file add

BUN_INSTALL="/home/YOUR_USERNAME/.bun"
PATH="$BUN_INSTALL/bin:$PATH"

Replacing YOUR_USERNAME with your real username (the current username can be found by typing 'whoami' in the terminal).

(Remember to save your changes with Ctrl-O)

Note: You will NEED TO OPEN A NEW SHELL for this to work OR type 'source ~/.bashrc' to use in the current terminal.

You should now be able to run bun commands in any new shell.

piyook
  • 41
  • 3
  • Your username should be lowercase() even it's capital letters `export BUN_INSTALL="/home/administrator/.bun" export PATH="$BUN_INSTALL/bin:$PATH"` – Bitfinicon Nov 27 '22 at 18:16
2

The installation script says a message at the end telling you how to add bun to your PATH manually. Here is that output:

Manually add the directory to your $HOME/.bashrc (or similar)

   BUN_INSTALL="/home/sno2/.bun"
   PATH="$BUN_INSTALL/bin:$PATH"

I advise you re-run the installation command and copy the environment variables and add them to your PATH.

sno2
  • 3,274
  • 11
  • 37
2
export BUN_INSTALL="/Users/manendra/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"

add these to your .bashrc, .zshrc or you can use export command to use for current session.

Note: Change your username place of (manendra) "/Users/manendra/.bun"

manendra
  • 101
  • 1
  • 4
2

If you have Node installed you can use

npm install -g bun
Vytenis
  • 21
  • 5
1

Manually add the directory to ~/.bashrc (or similar):

 export BUN_INSTALL="$HOME/.bun" 
 export PATH="$BUN_INSTALL/bin:$PATH"
Yunat Amos
  • 93
  • 4
0

The command export PATH=$PATH/root/.bun/bin/bun adds /root/.bun/bin/bun to the PATH environment variable.

The $PATH variable in the command represents the current value of the PATH environment variable. By appending /root/.bun/bin/bun to $PATH, you are adding this directory to the list of directories that the shell searches when you type a command. tory.

Note that this command assumes that the bun executable file is located in the /root/.bun/bin directory. If it is located in a different directory, you should modify the command accordingly.

If you have problem running bun in scripts. Check here.

/root/.bun/bin/bun

copy bun from there to this path. Or the path bun.service first check where bun is:

/usr/local/sbin

give permission to bun where it's first checked by the scripts. Be careful! Not the linux shell, but inside of scripts.

sudo chmod +x bun

to make ubuntu sudo environment variables available:

To make sudo bun available in Ubuntu, follow these steps:

  1. Open a terminal on your Ubuntu system.

  2. Use the sudo visudo command to edit the sudoers file:

sudo visudo
  1. Find the line that sets the secure_path. It will look something like this:
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
  1. Add the path to the bun executable (which is $HOME/.bun/bin) to the secure_path. You can use the $(echo $HOME) command to get your home directory dynamically:
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:$(echo $HOME)/.bun/bin"
  1. Save and exit the editor. In visudo, this is typically done by pressing Esc followed by :wq and pressing Enter.

  2. After saving the changes to the sudoers file, the sudo bun command should now be available.

Remember to be careful while editing the sudoers file, as any syntax errors can cause problems with your system. Always use visudo to edit the sudoers file to prevent such issues.

Bitfinicon
  • 1,045
  • 1
  • 8
  • 22
  • Beware that however it can not find the .env variable. it's undefined. You need to go that location and run or make `sudo bun` available – Bitfinicon Aug 03 '23 at 18:55
  • Ok, this is frustrating. You can't reach .env variables outside of its own directory `cd /usr/local/lsws/nodes/bun; bun /usr/local/lsws/nodes/bun/index.ts` Make this. Final solution right now. Or `cd /root/.bun/bin/bun /usr/local/lsws/nodes/bun; bun /usr/local/lsws/nodes/bun/index.ts` `/usr/local/lsws/nodes/bun` is where you script located as directory – Bitfinicon Aug 03 '23 at 19:13
-1

From the installer, last message is:

To get started, run

exec /bin/zsh bun --help

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 13 '22 at 10:19