Preface#
Using a
Linux
development environment onMac OS
is not difficult, asMac OS
itself is aUnix-like
system. WithHomeBrew
, mostLinux
software packages can be installed directly. Even without using a virtual machine, a relatively good development experience can be achieved. However, there may be special requirements, or one may not want to pollute the host machine's development environment. In that case, one can use tools likeVMware Fusion
,Parallels Desktop
, orVirtualBox
to install a complete Linux distribution in a virtual machine. However, these types of virtual machines are relativelyheavy
, slow to start, and consume a lot of memory, so they are not within my consideration. Of course, one can also useDocker Desktop
to directly use variousLinux
distribution images or create aDev Container
to create a fully equipped development image. However, currently, there is no one-size-fits-all solution for the issues withDocker
image sources, so that is also not within my consideration. Ultimately, I decided to useMechines
inOrbstack
to set up a development environment.
Installing Orbstack
#
You can directly download the installation package from the official website or install it using HomeBrew
.
brew install orbstack
Choosing a Suitable Distribution#
I am using Fedora
here.
Improving the Development Environment#
- The first step is of course to change to the
Tsinghua source. First, back up the default source.
sudo cp -r /etc/yum.repos.d /etc/yum.repos.d.backup
Then directly replace the default source.
sudo sed -e 's|^metalink=|#metalink=|g' \
-e 's|^#baseurl=http://download.example/pub/fedora/linux|baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora|g' \
-i.bak \
/etc/yum.repos.d/fedora.repo \
/etc/yum.repos.d/fedora-modular.repo \
/etc/yum.repos.d/fedora-updates.repo \
/etc/yum.repos.d/fedora-updates-modular.repo
If you prefer to change it manually:
-
Fedora repository (/etc/yum.repos.d/fedora.repo)
[fedora] name=Fedora $releasever - $basearch failovermethod=priority baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/$releasever/Everything/$basearch/os/ metadata_expire=28d gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch skip_if_unavailable=False
-
Updates repository (/etc/yum.repos.d/fedora-updates.repo)
[updates]
name=Fedora $releasever - $basearch - Updates
failovermethod=priority
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/updates/$releasever/Everything/$basearch/
enabled=1
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
-
Fedora-modular repository (/etc/yum.repos.d/fedora-modular.repo)
[fedora-modular] name=Fedora Modular $releasever - $basearch failovermethod=priority baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/releases/$releasever/Modular/$basearch/os/ enabled=1 metadata_expire=7d gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch skip_if_unavailable=False
-
Updates-modular repository (/etc/yum.repos.d/fedora-updates-modular.repo)
[updates-modular]
name=Fedora Modular $releasever - $basearch - Updates
failovermethod=priority
baseurl=https://mirrors.tuna.tsinghua.edu.cn/fedora/updates/$releasever/Modular/$basearch/
enabled=1
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False
```
-
Clean the cache.
sudo dnf clean all sudo dnf makecache
-
Update packages.
sudo dnf update
- Use
zsh
to replace the defaultbash
.
- Install
git
andzsh
.
sudo dnf install git zsh
- Install
oh my zsh
.
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
-
Install commonly used
oh my zsh
plugins.- Auto-suggestions.
git clone https://github.com/zsh-users/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
- Syntax highlighting.
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/fast-syntax-highlighting
```
- Auto-completion.
```bash
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git $ZSH_CUSTOM/plugins/zsh-autocomplete
```
-
Modify the
zsh
configuration file to change the plugins to:vim ~/.zshrc
plugins=( git zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete
)
- Apply the changes.
```bash
source ~/.zshrc
- Install
NVM
to manageNodeJS
versions.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
-
How to use:
$ nvm use 16 Now using node v16.9.1 (npm v7.21.1) $ node -v v16.9.1 $ nvm use 14 Now using node v14.18.0 (npm v6.14.15) $ node -v v14.18.0 $ nvm install 12 Now using node v12.22.6 (npm v6.14.5) $ node -v v12.22.6
For advanced usage, please refer to the documentation.
- Use
VS Code
to connect to the virtual machine just created.
- Install the
Remote Development
extension. - Add a remote connection. In the left menu, select Remote Explorer, click the
+
onSSH
, or use the shortcutShift
+Command
+P
and typeremote add
to open the window for addingSSH
connections.
Enterssh orb
to connect to the virtual machine just created.
::: warning
If there are multiple virtual machines, you need to specify which host to connect to when usingSSH
. If not specified, it will connect to the default host. For example,ssh debain@orb
connects to thedebain
host using the default user. Examples include
ssh machine@orb
,
ssh user@orb
,
ssh user@machine@orb
.
:::
This way, you have a development environment isolated from the host system. No matter how much you tinker, you don't have to worry. It's somewhat similar to
WSL
inWindows
, but it's simple and convenient, without needing to enable certain features of the system. You can use it directly after downloadingOrbstack
.
This article is synchronized and updated to xLog by Mix Space. The original link is https://remrin.dev/posts/linux/dev-env