I don't get it! What's the correct approach for starting VSCode (with sudo / chown)

Hi folks,

i hope so much that someone can give me some enlightment on this:

I’m new to Manjaro and but used to Linux (Ubuntu, Mint) but still far from being very good with it. So i now want to use VSCode on Manjaro and managed to install it (via the software installation tool, so i took the official community version code-oss.)
Everything worked fine.
But when I opened it I could not even create a file because of user rights.

So when I searched the internet for a solution, it to me became clear that i can solve this running vscode via sudo, which is not recommended, or when I change the user-rights using chown.
Which I did. This way I can create and edit (+ save) files, but still i can’t install any extension (in my case the extension metals for improved workflow in coding with scala) and similar works done. For example, metals wants to install a certain java environment for which user rights are missing (no permission…).
Which works when I run vscode using sudo.

So my question is (to which I could not find a good answer when searching the web for it):

What is the recommended way to do it? In other words: what should be the standard procedure when installing and working with vscode?
Change all user rights to the currently used user?
(program binary + program folder + all repositories and code that i’m working on)

How do you guys do it? What’s the intended way to go in such situations. I don’t seem to really have understood the linux / unix way of doing things concerning user rights.

I know I should avoid running applications as sudo if not necessary. But if i have to create and change files all the time, switch between repositories (which normally have all permissions set to “root” by default), what’s the way to go?

Any help will be appreciated. Also just some links about general knowledge on the topic. I know how to USE chown and sudo, but I don’t know in what kind of situations I should use it.

(Sorry for my English btw I’m not a native speaker).

Thanks a lot in advance!

Where do you want it to create a file?

1 Like

I don’t why the first approach to “I can’t read/write my own files” is “let’s run this as root”. I guess it’s from that awful Windows philosophy “open as administrator” and badly programmed programs. However, it doesn’t apply to any Linux.

If you run something with sudo, you change the user to root. This has its own home directory, own system services, own settings for everything, with the additional capabilities to be able to read and write everything.
This comes at a great risk: If you start an application as root and it doesn’t check for this, it can read and write everything. I remember anecdotal that steam did something like this when uninstalling: It removed itself, then went up the directory tree untill / and removed everything. It’s bad if running this as your own user, but imagine doing this as root: It removed everything.

So, running anything with sudo, is never a good idea. Ask yourself first: “Do I want to edit system files (in /boot or /etc?” If not, then you don’t need sudo.
(If someones still suggests to run something as sudo, think first!)

I don’t know VSCode but I guess the workspace is somewhere in ~/workspace or anything under your user’s home, so you never will have problems with access rights.

1 Like

Wow, thanks for these answer! They really are helping me out! I’m just reading through the linked tutorial (which is just awesome!) posted by @maycne.sonahoz but it takes some time as it’s a lot of content :slight_smile:

@mithrial thanks a lot now i see that i was missing a lot of points concerning user rights. It’s getting a lot clearer now thanks to your good explanation.

I will read the tutorial and try if this answers my questions and if I still have some questions i will post them here.

Thanks a lot so far!

How do u install VSCode? I use it on manjaro for years. Install via pamac

A lot of patience is needed - when I moved to Manjaro from Linux Mint I was so accustomed to starting up a file manager with root privilege to manage wallpapers and stuff… with Dolphin it’s not so simple.

VSCode, on the other hand, is well written. You can open a text file, but when you try to save it - then it will ask for sudo password.

To create a file, you can simply browse to the folder you want to make it, then press F4 to get a terminal and type ‘sudo touch file.txt’ - then open that file with ‘code file.txt’.

Regarding extensions with the code-oss version I could not find some of the ones I usually use so this probably the issue you are having. When I installed the Snap version I could find every extension.

yes i also installed it via pacman (gui version, but still).
I think it works fine, I had some problems with probably the wrong owner set to my files (more below…)

i can find all extensions (so far) with the pacman version, too.

So in general now this is what I did and what resulted from that:
(also an answer your post Ben)
I solved my problems concering saving files by changing the owner of the repositories that I’m working on to my user (via chown). Now that works fine and I don’t have to do such “workarounds” any more.

So question 1:
Is this the way to go? Change to user-rights of the repos and the code that i’m working on to my user? Before it was set to “root”.
Is it correct that ALL files in /home/username should have the rights set to (or be owned by) my user?

So this way everything worked out fine, but TWO PROBLEM STILL REMAINS:

Problem 1:
If using vscode to work on a project written in the language Scala. Therefore I use the extension “metals” (Scala language server with rich IDE features). The problem is that without running vscode as sudo, metals cannot start up a server which means metals is not working. Running vscode as sudo makes it work…

Problem 2:
Running vscode as sudo, I can’t use git for the repo that i’m working on, because it’s owned by my user and not by root. (error message (translated): repository belongs to someone else)

So I still have problems how to do things with vscode. Or maybe it’s a more general thing of how to handle files, apps (in this case IDEs) and user rights…

Anyone also using metals or other extension and knows how to solve my issue?

Thanks for all your replys so far!! :*

Ok :slight_smile: Everything solved now! YEEEEAAAAH! :slight_smile:

The problem was that some stuff (extension metals) was installed using sudo, so when running my repo which I gave file permissions to my user (using chown ), all permissions were kind of mixed up.
My own code was owned by my user, while all files that the extension metals had created automatically (build stuff like target and project) was owned by root.

So when I ran vscode as a user i could not work with these root-owned directories and metals couldn’t start up correct. So some errors were thrown.

And when I ran vscode using sudo i couldn’t handle my git repo using vscode’s git extension. because it was all ownded by my user, not root.

So the solution was to deinstall metals (because it was previously installed using sudo thus owned by root), delete all directories automatically created by metals and bloop. just to make sure, I also “chowned” my whole repository.

Then I installed metals again (NOT using sudo), and finally everything works fine!

Running vscode NOT using sudo but as a normal user, using metals, using git.

Only deinstalling metals was not enough, it was important to put my repository in a consistent state so that ALL files are owned by my user now.

I hope someone else can profit from (my wasted hours put into ) this solution now! :slight_smile:


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