简体   繁体   中英

How to develop on a virtual machine?

I want to edit source code on a virtual machine running Ubuntu. I'm ssh'd into it to preserve my native (mac) key bindings (eg copy and paste). Can I route terminal data through to sublime on the host side? Can I invoke the sublime editor in the vm and use it with X11 forwarding?

I'm just looking for the common workflow where I can keep using the key-bindings and editor I've learned to love.

You can use Samba share for this. (Assuming that you are running windows). That's the way I do it.

How to Create a Network Share Via Samba Via CLI (Command-line interface/Linux Terminal) - Uncomplicated, Simple and Brief Way!

or you can check How to map a network drive?

You have a few options:

  • You can install Samba for SMB network sharing, or Netatalk for AFP network sharing, as suggested in the answer by Ahmed Daou. Probably the most flexible solution once set up. If you want to get fancy you can also install avahi-daemon so that you can browse to network files from the Finder, as you would any other file share; otherwise you can use "Connect To Server..." from the Finder's Go menu.

  • You can round-trip it with scp. Install a public-private keypair for SSH so you don't have to enter a password every time out (even if you use a passphrase, your Mac will remember it in its keychain). When you quit Sublime, the saved file will be will copied back to the VM.

Example sublime_open script:

#!/bin/bash

serverAddress="username@myvm.local"
if [[ ! $1 ]]; then
    echo "usage: sublime_open <remoteFilename> [username@serverAddress] [serverPort]"
    exit 1
fi
[[ $2 ]] && serverAddress="$2"
[[ $3 ]] && serverPort="-P $3" || serverPort=
scp $serverPort $serverAddress:"$1" /tmp/myfile.txt
/Applications/"Sublime Text.app"/Contents/MacOS/"Sublime Text" /tmp/myfile.txt
scp $serverPort /tmp/myfile.txt $serverAddress:"$1"
rm /tmp/myfile.txt &> /dev/null
  • You can, as you suggested, use X11 and run the Linux version. Install XQuartz on your Mac, and then open an SSH session to your VM with the -X option, eg ssh -X myvm.local . Then in that Terminal window run ./sublime_text from whatever directory it lives in (if you install the Ubuntu/Debian package, it appears to be in /opt/sublime_text/sublime_text ). It will open in an X window on your Mac.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM