I'm running a WSL Debian distro because I wanted to follow along with the InterMezzOS tutorials. I followed the installation instructions for Rust and ran curl https://sh.rustup.rs -sSf | sh
, but I can only make the rustc
command available by running source $HOME/.cargo/env
AFTER running sudo su
, and when I exit sudo
I can't call it, and when I retype sudo su
it doesn't work anymore, I have to type it again.
Is there any way I can make it available so the commands work every time I open my shell, without running sudo
every time?
Right after you install Rust, you can find where it was installed in the Linux filesystem by running whereis rustc
It should output something like this:
rustc: /home/damianrivas/.cargo/bin/rustc
You need to add that to your path, so open up .bashrc
in an editor
nano ~/.bashrc
(if you use zsh like I do just replace it with ~/.zshrc
)
Scroll down to the bottom of the file (or use the keyboard shortcut alt + /
, and add Rust's location to PATH
by adding this at the end:
# Add Rust to $PATH
export PATH="$HOME/.cargo/bin:$PATH"
I have $HOME
because /home/damianrivas/
is my $HOME
path. I could've also put
export PATH="/home/damianrivas/.cargo/bin:$PATH"
After this is done, exit all of your open WSL terminals before opening up a new one. You can restart your PC to be sure. Then run rustc --version
when you open up a new terminal and it should work.
Notice that curl https://sh.rustup.rs -sSf | sh
will add to /home/<user>/.profile
a line that appends binaries in ~/.cargo/bin
, including rustup and rustc. The addition of the binaries in .cargo
however does not take immediate effect. An easy way to associate it with your bash terminal is (immediately after installation):
echo $(cat ~/.profile | tail -1) >> ~/.bashrc
source ~/.bashrc
In your particular case, since you are root, you should copy /root/home/.cargo
and /root/home/.profile
into your own users home directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With