首页 最新 热门 推荐

  • 首页
  • 最新
  • 热门
  • 推荐

使用树梅派搭建Golang、Python、NodeJs的开发服务器

  • 25-03-05 12:41
  • 2190
  • 8110
blog.csdn.net

使用树梅派搭建Golang、Python、NodeJs的开发服务器

最终效果图

使用浏览器就可以进行Go、Python、NodeJs等开发任务
在这里插入图片描述

安装系统

  1. 安装rpi-imager

    sudo apt install rpi-imager
    
    • 1
  2. 打开rpi-imager烧写Raspberry Pi OS Lite(64-bit)系统

  3. 设置好用户名、密码、wifi、ssh等信息

  4. 上电

修改镜像源

  1. 备份/etc/apt/sources.list

    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
    
    • 1
  2. 修改/etc/apt/sources.list

    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
    
    deb https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
    # deb-src https://security.debian.org/debian-security bookworm-security main contrib non-free non-free-firmware
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  3. 修改/etc/apt/sources.list.d/raspi.list

    deb https://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ bookworm main
    
    • 1

    参考:raspberrypi | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

  4. 更新

    sudo apt update && sudo apt dist-upgrade
    
    • 1

安装docker

  1. 删除旧版本

    for pkg in docker.io docker-doc docker-compose \
     podman-docker containerd runc; \
    do sudo apt-get remove $pkg; done
    
    • 1
    • 2
    • 3
  2. 设置apt 仓库

    # Add Docker's official GPG key:
    sudo apt-get update
    sudo apt-get install ca-certificates curl
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc
    
    # Add the repository to Apt sources:
    echo \
     "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] \
     https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian \
     $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
     sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
  3. 安装docker

    sudo apt-get install docker-ce docker-ce-cli \
       containerd.io docker-buildx-plugin docker-compose-plugin
    
    • 1
    • 2
  4. 验证安装

    sudo docker run hello-world
    
    • 1
  5. 将用户添加到docker组

    sudo groupadd docker
    sudo usermod -aG docker $USER
    newgrp docker
    
    • 1
    • 2
    • 3

使用docker创建开发服务器

  1. 创建项目文件夹

    mkdir code-server && cd code-server
    
    • 1
  2. 创建Dockerfile

     FROM codercom/code-server:ubuntu
    
     USER root
     # 修改源
     RUN sed -i 's#http://ports.ubuntu.com/ubuntu-ports/#https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/#g' /etc/apt/sources.list
    
     RUN apt update -y && apt upgrade -y
    
     # 设置时区
     ENV TZ="Asia/Shanghai"
     RUN DEBIAN_FRONTEND=noninteractive apt-get install -yq tzdata && \
         ln -fs /usr/share/zoneinfo/$TZ /etc/localtime && \
         dpkg-reconfigure -f noninteractive tzdata
     USER 1000
    
     ENV USER=coder
    
     WORKDIR /home/coder
    
     RUN sudo apt install build-essential libssl-dev zlib1g-dev \
             libbz2-dev libreadline-dev libsqlite3-dev curl \
             libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev -y
    
     # install python
     RUN curl https://pyenv.run | bash
    
     RUN export PYENV_ROOT="$HOME/.pyenv" \
         && export PATH="$PYENV_ROOT/bin:$PATH" \
         && eval "$(pyenv init -)" \
         && pylatest=$(pyenv install -l | grep -E '^  ([0-9].)([0-9]+.)([0-9]+)$' | tail -n1) \
         && pyenv install $pylatest \
         && pyenv global $pylatest \
         && python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip \
         && pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple \
         && echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc \
         && echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc \
         && echo 'eval "$(pyenv init -)"' >> ~/.bashrc
    
     # 安装nodejs
     RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \
         && export NVM_DIR="$HOME/.nvm" \
         && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \
         && nvm install $(nvm ls-remote | grep LTS | tail -n1 | awk '{print $1}') \
         && npm config set registry https://registry.npmmirror.com \
         && npm install -g npm
    
     # 安装go
     ENV GO111MODULE=on \
         GOPROXY=https://goproxy.cn,direct
     RUN wget https://go.dev/dl/go1.22.2.linux-arm64.tar.gz \
         && sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.22.2.linux-arm64.tar.gz \
         && export PATH=$PATH:/usr/local/go/bin \
         && echo 'export PATH=$PATH:/usr/local/go/bin' >> .bashrc \
         && rm go1.22.2.linux-arm64.tar.gz 
    
     RUN rm -rf ~/workspace/pyenv
    
     RUN sudo apt install vim tree -y
    
     # 修改提示符显示最后一个文件夹
     RUN sed -i 's/\(PS1.*\)\\w/\1\\W/g' ~/.bashrc
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
  3. 创建docker-comose.yaml

    services:
      code-server:
        build: .
        container_name: code-server
        user: "${UID}:${GID}"
        environment:
          - DOCKER_USER=$USER
        volumes:
          - ./.config:/home/coder/.config
          - ./.local:/home/coder/.local
          - ~/code:/home/coder/workspace
          - ~/.ssh:/home/coder/.ssh
        ports:
          - 8080:8080
        restart: unless-stopped
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
  4. 创建配置文件夹用于挂载

    mkdir .config .local
    
    • 1
  5. 启动容器

    docker compose up -d
    
    • 1
  6. 浏览器访问本机的8080端口,即可进入web版的vscode,登陆密码可以在./.config/code-server/config.yaml文件查看

    登陆页面

推荐阅读

1. Go语言中局部变量的逃逸分析(从汇编的角度)
2. 使用VS Code调试Go程序

文章知识点与官方知识档案匹配,可进一步学习相关知识
Python入门技能树首页概览433049 人正在系统学习中
注:本文转载自blog.csdn.net的gopyer的文章"https://blog.csdn.net/fuxily/article/details/139212659"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接
复制链接
相关推荐
发表评论
登录后才能发表评论和回复 注册

/ 登录

评论记录:

未查询到任何数据!
回复评论:

分类栏目

后端 (14832) 前端 (14280) 移动开发 (3760) 编程语言 (3851) Java (3904) Python (3298) 人工智能 (10119) AIGC (2810) 大数据 (3499) 数据库 (3945) 数据结构与算法 (3757) 音视频 (2669) 云原生 (3145) 云平台 (2965) 前沿技术 (2993) 开源 (2160) 小程序 (2860) 运维 (2533) 服务器 (2698) 操作系统 (2325) 硬件开发 (2492) 嵌入式 (2955) 微软技术 (2769) 软件工程 (2056) 测试 (2865) 网络空间安全 (2948) 网络与通信 (2797) 用户体验设计 (2592) 学习和成长 (2593) 搜索 (2744) 开发工具 (7108) 游戏 (2829) HarmonyOS (2935) 区块链 (2782) 数学 (3112) 3C硬件 (2759) 资讯 (2909) Android (4709) iOS (1850) 代码人生 (3043) 阅读 (2841)

热门文章

101
推荐
关于我们 隐私政策 免责声明 联系我们
Copyright © 2020-2024 蚁人论坛 (iYenn.com) All Rights Reserved.
Scroll to Top