Install rust on a VPS, as root or as a user?

Hi everyone, noob question here.
I'm excited to manage my very first VPS and start playing around. I've got root access to a linux machine and I just installed cargo rustc and rustup with the allmighty command :

curl https://sh.rustup.rs -sSf | sh

So the installer tells me :

directory, located at:

  /root/.cargo/bin

This path will then be added to your PATH environment variable by modifying the
profile file located at:

  /root/.profile

And now I'm wondering : should I install such stuff from root privileges, or should I do it from a user account + sudo ?

You should probably just use a regular user account, and you don't need to sudo for installing rust.

1 Like

this ^^ the suggested way is to install as user,
there is no point installing rustup as root (either through sudo or directly) because there is no system-wide install that way, .rustup cannot be shared between users

Okay thanks. Should I uninstall as root and reinstall as a user?

yes probably
it'd free up some space, and having one install is probably confusing enough to start with :smile:

1 Like

Also, depending on the specs of the VPS you chose, building Rust code on your server might fill up the available disk space in no time (not even speaking of the usually abysmal CPU performance when compiling and the limited RAM which might run out during linking).

I have had nothing but pain compiling Rust code on my VPS, so I build the code locally in a Docker container instead (such that the resulting binary is linked against the same library versions as are available on the VPS, independent of the local machine I'm running it on) and copy the resulting binary over to the server.

2 Likes

Also keep in mind, that installing rust as a root user will not add the rust components (rustc, rustup, cargo, etc) to your personal $PATH but to the root $PATH.

Then you can't just run cargo build but have to type /root/.cargo/bin/cargo.

I assume, this isn't what you intend, so just install it as a regular user. The whole rust stack will be installed to your home directory, which does not require any super permissions.

1 Like

That is all very informative and relevant, thank you very much for your tips and insights. I love this forum.

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