Rustup not working with sudo

I recently got a new computer running ubuntu, and I installed rust using:

curl --proto '=https' --tlsv1.2 -sSf | sh

as instructed I closed the terminal, and logged back in, so that rustup command would be in my path.

I then changed switched to rust nightly using

rustup default nightly

All seemed to be working, but I noticed that trying to use rustup in sudo doesn't seem to work.

When I type the command : sudo rustup *any subcommand* , I just get the response "sudo: rustup: command not found"

How can I fix this?

Rustup is installed in your user's home directory somewhere. You shouldn't be using rustup with sudo.

1 Like

Is it possible to run rustup with sudo?

One possible way might be sudo -E rustup whatever (-E flag commands sudo to inherit executer's environemt) but why do you need to run rustup as superuser?
It is intended to be run as user and I cant imagine any scenario where you need to use it as root.
If you are trying to globally install things with rustup what you can do is
Either add you rust installation folder to PATH variable in /etc/environment file for you give user permissions to /usr/local/bin or anything like that and link installed thing there using ln -s

You may damage your Rust installation if you use rustup with sudo.

Rustup installs Rust per user (i.e. for you only, not system-wide, not for root). If you use sudo to impersonate root or another user, and make it change your personal Rust install, it will screw up permissions of your personal Rust installation and it will no longer be usable by you.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.