Rustup and system-wide rust

I have Rust installed from my distribution. I want to have a different version of rust (f.e. nightly) to be installed somewhere locally on my machine. Rustup does not allow this:

error: it looks like you have an existing installation of Rust at:
error: /usr/bin
error: rustup cannot be installed alongside Rust. Please uninstall first
error: if this is what you want, restart the installation with `-y'
error: cannot install while Rust is installed

I wonder if there is a way to have those to peacefully coexist. For Python we have virtualenv which allows to have a specific python version and all dependencies to be completely confined (even with pip installs going into right place). Is such thing exists for Rust?

Uninstall distro Rust and let rustup manage both stable and nightly.

Distro Rust versions are usually hopelessly outdated, so if you have rustup, there's no point using anything else.

2 Likes

To be honest, the same can be said for python and gcc. At the same time virtualenv allows to keep system python intact while permitting fresh version.

System rust have dependencies, and distribution provide the way to manage them. If I install rust-gdb, it installs gdb package, if I install rustc, it gives me a proper (compatible) version of libc-dev, binutils, libstdc++6, etc. Loosing this by replacing it with curlbash would be a real loss.

Btw, in my distro Rust is 1.36, and it does not sound as 'hopelessly outdated'.

In that case you have to ask your distro for rustc-nightly.

This is unsolved problem for Rust. Linux distros move to slowly for a 6-week release schedule, and rustup doesn't want to be managing packages for all distros.

1 Like

It's kinda unfriendly to choose between a stable distro version and a bleding edge. As I said, virtualenv for Python can do the trick providing bleeding edge within confined directory. It does so by setting up environment variables (to redirect all operations into local directory instead of system one).

I wounder if having the same thing for Rust would be a great thing...

Note that there is no non-bleeding-edge version of Rust. Rust stable releases are supported for 6 weeks. What distros ship is not stable, but outdated and unsupported by the Rust team.

1 Like

As a distro packager for Fedora and RHEL, please do use those packages! It's totally feasible to interoperate with rustup:

2 Likes

For note, if you really want to install a local rust in addition to a system rust, I recommend asdf. A quick setup example:

Acquire it:

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.7.4

Have your shell load it:

Bash:

echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.bashrc
echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.bashrc

ZSH:

echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.zshrc
echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.zshrc

Fish:

echo 'source ~/.asdf/asdf.fish' >> ~/.config/fish/config.fish
mkdir -p ~/.config/fish/completions; and cp ~/.asdf/completions/asdf.fish ~/.config/fish/completions

Etc...

Then reload your shell, or source it, or whatever to load it.

Install a language plugin

Can run just asdf for help.

List the officially supported plugins (can install others via git or filesystem or so):

asdf plugin-list-all

Install rust's plugin:

asdf plugin-add rust

Install a rust version

Can list the versions it supports from rust specifically (it pulls from the main rust build distribution system):

asdf list-all rust

Let's install nightly:

asdf install rust nightly

You can set it to be used everywhere for your user with:

asdf global rust nightly

Or just for the current directory tree:

asdf local rust nightly

Can switch back to the system version with the special version named system, like:

asdf global rust system

You can install many versions of rust:

asdf install rust stable
asdf install rust 1.37.0

And can use them in many directories.

Do note, asdf only downloads for the x86 platform, no cross compiling or anything like that for that you will still want rustup or a docker container (I prefer docker for reproduciblity anywhere). But asdf is awesome for simple things like this (though I use rustup for rust, it's super useful for a lot of other languages and tools).

1 Like

The difference between Python and rustc is that you need python both for development and for running the program. The programs rustc produces are standalone programs that don't depend on Rust being installed on the target system. As such, rustc is purely a development package, in contrast to Python.

This gives you two options: you want to develop and use with only what the OS gives you. Then use the system packages. That's what they are there for! The other option is that you want access to all things that the Rust project offers you (including the version that your package manager ships): use rustup exclusively.

If the issue arises that you want to test against systems Rust or use it regulary, then do what @cuviper says, it's important to test against your target system.

3 Likes

I have both a distro rustc and rustup installed, and they coexist just fine. I don't remember what I did, but I also don't remember having seen the message you've seen.

cuviper, thanks a lot! This is exactly the thing I wanted to have.

1 Like

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