7

I am setting up Visual Studio Code on Linux.

Since the machine is shared, my $HOME folder is restricted in size, leaving me no space for extensions (which are stored in $HOME/.vscode/), and that fails my attempts to install them.

I do have enough space on other development directory, but I couldn't find a way to tell Visual Studio Code to use another path, rather than $HOME, for the global .vscode folder.

Is there a way to do that without changing my $HOME?

EDIT
While the suggestion in the comment solved the issue of extensions being installed in a different folder - there's a HUGE .cache folder that's being filled by vscode in my $HOME folder...
Is there a way to somehow change to path to this one as well?

5
  • 2
    have you tried the command line option --extensions-dir and --user-data-dir, code.visualstudio.com/docs/editor/… Commented Dec 8, 2020 at 12:16
  • Yes! That helped. Commented Dec 8, 2020 at 15:50
  • 2
    Why dont you create a folder on disk that you want it on and link it to your home folder with ln -s <source path> /home/$USER/.vscode Commented Feb 13, 2021 at 11:30
  • can I use this trick to redirect the .cache folder? Commented Feb 14, 2021 at 8:23
  • Hi @so.very.tired, just as a clarification: what you want to achieve is to keep everything taking up considerable disk space outside of $HOME? As long as that is achieved, having e.g. the user settings in $HOME isn't a problem? Commented Feb 20, 2021 at 8:49

1 Answer 1

6

Some options in order of recommendation:

Use custom directories for extensions and user data

Your best option is probably to tell VS Code to use custom paths for extensions and user data. This would work since it would be the extensions and cache folders that take up disk space, and since the cache folders are located under the user data folder.

You provide the custom paths as command line arguments when invoking VS Code. Using /mnt/extdir/vsc-ext/ and /mnt/extdir/vsc-user-data/ as examples for desired external directories, you'd use:

$ code --extensions-dir /mnt/extdir/vsc-ext/ --user-data-dir /mnt/extdir/vsc-user-data/ . 

You can add an alias to your shell startup script to facilitate this:

alias code='code --extensions-dir /mnt/extdir/vsc-ext/ --user-data-dir /mnt/extdir/vsc-user-data/' 

Then you can continue to use just e.g. code . as usual, but have VS Code use the external directories for extensions and cache.

From the CLI documentation:

--extensions-dir <dir>

Set the root path for extensions. Has no effect in Portable Mode.

--user-data-dir <dir>

Specifies the directory that user data is kept in, useful when running as root. Has no effect in Portable Mode.


Just a side note: I ran the following to confirm that the cache folders are actually under the user data directory:

$ mkdir vs-user-data && code --user-data-dir vs-user-data . && sleep 3 && ls vs-user-data | grep -i cache CachedData Code Cache GPUCache 

Use portable mode

Using portable mode (documentation), all user data is stored in the installation directory, which is chosen by you.

This would probably work fine in your case, but a drawback would be a non-standard way for installation and making updating VS Code more cumbersome.

Use symlinks

That would probably work as well, but would be an inferior option. The other solutions given above are officially supported and more robust.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.