Richard
Richard

Reputation: 65600

Vagrant: how to edit files on the Vagrant server?

I'm following these instructions for setting up a Django app on Vagrant.

I have successfully completed them and started Django, but: how can I now edit the Django files within my usual text editor, TextMate?

I guess I can ssh and use vi to edit them from the command line, but I thought the point of Vagrant was to be able to use my usual editing tools.

I'm just not sure where the Django files are physically located.

Apologies if this question is off-topic, I'll happily post it elsewhere, if editors can let me know where is best.

Upvotes: 5

Views: 5856

Answers (2)

Tanay Joshi
Tanay Joshi

Reputation: 1

Vagrant always synchronizes the files in the project you set up with your PC.

So whenever you ssh into the vagrant, (usually) in /vagrant directory you can see all the files you have in the root folder of your project (directory where Vagrantfile ruby script is)

Now you can use your text editor and save the file in a folder you want (for convenience, always save new files inside the project directory). now mirroring your directory structure around the /vagrant directory you can see the file being saved in the appropriate folder in your guest machine.

For e.g if you created and saved a file in your project root folder then you can see it appear in /vagrant directory.

Upvotes: 0

FlipperPA
FlipperPA

Reputation: 14361

That web site is exactly the same place I started a few months ago.

Since I've learned more about Vagrant since then, I've created my own GitHub repo. You can download it here:

https://github.com/FlipperPA/djangovagrant

The way it is setup:

  • git clone the repo to a local directory on your machine
  • cd into that directory
  • run "vagrant up"
  • the directory you run "vagrant up" in is mapped to /vagrant on the guest virtual machine

Here is a working example of the way one might do it:

cd $home
git clone https://github.com/FlipperPA/djangovagrant.git
cd djangovagrant
vagrant up
vagrant ssh djangovm
cd /vagrant
django-admin.py startproject django_project
cd django_project
python manage.py runserver [::]:8000

You will then see the Django Project build on your local machine in the "djangovagrant" folder you created by the clone command above. You can you Textmate, Sublime, or any text editor you like to edit the files locally, and they'll be mapped to the guest VM.

I hope this helps - good luck.

Upvotes: 1

Related Questions