{"id":4658,"date":"2024-01-27T13:07:15","date_gmt":"2024-01-27T13:07:15","guid":{"rendered":"https:\/\/nikola-breznjak.com\/blog\/?p=4658"},"modified":"2024-01-27T13:07:15","modified_gmt":"2024-01-27T13:07:15","slug":"solving-the-retry-as-admin-while-saving-files-in-visual-studio-code-on-a-mac","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/quick-tips\/solving-the-retry-as-admin-while-saving-files-in-visual-studio-code-on-a-mac\/","title":{"rendered":"Solving the &#8216;Retry as Admin&#8217; while saving files in Visual Studio Code on a Mac"},"content":{"rendered":"<h2>TL;DR<\/h2>\n<p>If you ever get an error that you can&#8217;t save a file in Visual Studio Code, and it prompts you to &#8216;Retry as Admin&#8217; (where you then have to enter your admin password) then the solution is super easy by using the <code>chown<\/code> command.<\/p>\n<p>Namely, you just have to run <code>sudo chown -R $USER .<\/code> in the folder where your file is located and that will &#8216;fix it&#8217;.<\/p>\n<p>Yep, not much else to it really \ud83d\udcaa<\/p>\n<h2>Why does this happen?<\/h2>\n<p>Now, this may have happened if you were using <code>sudo<\/code> when installing some Node.js packages with <code>npm<\/code> (or some other package manager), or if you created the folder (not sure why, but still plausible) using the <code>sudo<\/code> command.<\/p>\n<h2>A bit more about the chown command<\/h2>\n<p>The <code>chown<\/code> command in UNIX and Linux-based systems (including MacOS), stands for &#8216;change owner&#8217; and it&#8217;s used to change the ownership of files and directories.<\/p>\n<p>A detailed breakdown of the above command is as follows:<\/p>\n<ul>\n<li><strong>sudo<\/strong>: shorthand for &#8216;superuser do&#8217;; it grants administrative privileges for the command that follows. And yes, you&#8217;re right, <strong>you should use this command with caution<\/strong><\/li>\n<li><strong>chown<\/strong>: the command to change file&#8217;s owner<br \/>\n&#8211;<strong>R<\/strong>: this option makes the command recursive, which means it will apply to all files and directories within the current directory<\/li>\n<li><strong>$USER<\/strong>: This is a variable that represents the current logged-in user (aka you). By using $USER, you&#8217;re changing the ownership of the files to yourself, eliminating the need for using <code>sudo<\/code> later<\/li>\n<li><strong>.<\/strong>: the dot represents the current directory. So, the command affects the files and directories where it&#8217;s executed<\/li>\n<\/ul>\n<h2>Thread with caution<\/h2>\n<p>It&#8217;s important to understand why you&#8217;re using <code>chown<\/code>, because incorrect usage can lead to permission issues or security risks. Generally, use it when you need to restore file ownership to the correct user after it&#8217;s been changed (often inadvertently). Be very vary of following tutorials (or any other instructions) that tell you to set the file permissions to anything else but you ($USER).<\/p>\n<h2>Learn even more about chown<\/h2>\n<p>If you want to learn more about the <code>chown<\/code> command and its options, you can run the <code>man chown<\/code> command in your terminal and you&#8217;ll get way more detailed documentation. Or, of course, just <a href=\"https:\/\/www.google.com\/search?q=chown\">Google<\/a>.<\/p>\n<p>Hope this quick tip helps \ud83d\ude4c<\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR If you ever get an error that you can&#8217;t save a file in Visual Studio Code, and it prompts you to &#8216;Retry as Admin&#8217; (where you then&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4659,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-4658","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-quick-tips"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/4658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=4658"}],"version-history":[{"count":0,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/4658\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/4659"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=4658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=4658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=4658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}