.bashrc: Permission denied

前端 未结 4 1749
陌清茗
陌清茗 2020-12-28 16:42

I try to work with a project in vagrant. I have made the command vagrant ssh, and connected to VM. Now I need to edit .bashrc file to set path to

相关标签:
4条回答
  • 2020-12-28 17:15

    The .bashrc file is in your user home directory (~/.bashrc or ~vagrant/.bashrc both resolve to the same path), inside the VM's filesystem. This file is invisible on the host machine, so you can't use any Windows editors to edit it directly.

    You have two simple choices:

    1. Learn how to use a console-based text editor. My favourite is vi (or vim), which takes 15 minutes to learn the basics and is much quicker for simple edits than anything else.

      vi .bashrc

    2. Copy .bashrc out to /vagrant (which is a shared directory) and edit it using your Windows editors. Make sure not to save it back with any extensions.

      cp .bashrc /vagrant ... edit using your host machine ... cp /vagrant/.bashrc .

    I'd recommend getting to know the command-line based editors. Once you're working inside the VM, it's best to stay there as otherwise you might just get confused.

    You (the vagrant user) are the owner of your home .bashrc so you do have permissions to edit it.

    Once edited, you can execute it by typing source .bashrc I prefer to logout and in again (there may be more than one file executed on login).

    0 讨论(0)
  • 2020-12-28 17:21

    If you can't access the file and your os is any linux distro or mac os x then either of these commands should work:

    sudo nano .bashrc
    
    chmod 777 .bashrc 
    

    it is worthless

    0 讨论(0)
  • 2020-12-28 17:23

    If you want to edit that file (or any file in generally), you can't edit it simply writing its name in terminal. You must to use a command to a text editor to do this. For example:

    nano ~/.bashrc
    

    or

    gedit ~/.bashrc
    

    And in general, for any type of file:

    xdg-open ~/.bashrc
    

    Writing only ~/.bashrc in terminal, this will try to execute that file, but .bashrc file is not meant to be an executable file. If you want to execute the code inside of it, you can source it like follow:

    source ~/.bashrc
    

    or simple:

    . ~/.bashrc 
    
    0 讨论(0)
  • 2020-12-28 17:25

    .bashrc is not meant to be executed but sourced. Try this instead:

    . ~/.bashrc
    

    Cheers!

    0 讨论(0)
提交回复
热议问题