Ubuntu常用环境配置

该文提供了Ubuntu系统的详细配置步骤,包括切换清华源、安装常用软件(如Git、ZSH、Node.js、Anaconda和Jupyter)、配置SSH、DNS、代理以及使用frp进行内网穿透。此外,还涉及到了一些开发工具的优化设置,如ZSH的主题和插件,以及Python环境管理Pyenv的使用。
摘要由CSDN通过智能技术生成

配置软件源

切换清华源

sudo sed -i "s@http://.*archive.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@https://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sudo apt update -y
sudo apt upgrade -y

常用软件安装

基础软件安装

常用的一些环境包括编译环境

sudo apt install -y curl proxychains-ng vim openssh-server net-tools make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils liblzma-dev tk-dev python3-pip tree

代理

配置proxychains-ng

下面有某些软件可能无法访问,所以先配置代理

# 将192.168.3.104 10808 修改为自己的代理服务器地址
sudo sed -i 's/socks4[[:space:]]*127.0.0.1 9050/socks5\t192.168.3.104 10808/' /etc/proxychains4.conf

系统代理

设置

export ALL_PROXY="socks5://127.0.0.1:1080"
export all_proxy="socks5://127.0.0.1:1080"

取消

unset ALL_PROXY
unset all_proxy

常用配置

临时设置DNS

sudo sed -i '1i\nameserver 8.8.8.8' /etc/resolv.conf

设置默认编辑器

update-alternatives --config editor

配置ssh

允许root登陆

sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

设置开机启动

sudo systemctl enable --now ssh

常用软件安装

git

安装

sudo apt install git -y

配置

  1. 生成公钥
git config --global user.name "名字"
git config --global user.email "邮箱地址"
ssh-keygen -t rsa -C '邮箱地址'
  1. 复制公钥并配置到github
cat ~/.ssh/id_rsa.pub 

git代理设置

git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'

git代理取消

git config --global --unset http.proxy
git config --global --unset https.proxy

zsh

安装

sudo apt install zsh -y

配置

  1. 安装oh-my-zsh插件 https://ohmyz.sh/#install
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

国内DNS可能有污染,若失败试试换DNS
2. 配置插件
下载插件的插件

## 自动提示
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
## 高亮
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  1. 修改配置文件
    编辑 ~/.zshrc
# 分别找到这两行代码
ZSH_THEME="robbyrussell"
plugins=(git)

# 分别替换成下面的
## 自定义随机主题(几个好用的)
THEMES=(darkblood bira duellj fino-time fox gnzh xiong-chiamiov-plus jonathan random)
## zsh中读取数组是从一开始算
ZSH_THEME=${THEMES[$((1 + ($RANDOM % ${#THEMES[*]})))]}

plugins=(git z zsh-syntax-highlighting zsh-autosuggestions)

或者执行命令

sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="jonathan"/' ~/.zshrc
sed -i 's/plugins=(git)/plugins=(git z zsh-syntax-highlighting zsh-autosuggestions)/' ~/.zshrc
source ~/.zshrc
  1. 显示优化(可选)
    ls -al显示的时间改为%Y-%m-%d %H:%M:%S'格式
export TIME_STYLE='+%Y-%m-%d %H:%M:%S'

Node

通过nvm安装node

# 下载安装nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
# 重新进入bash(zshrc)或重新加载.bashrc(.zshrc)
source ~/.zshrc
# 安装node
nvm install v16.17.0
# 设置默认
nvm alias default v16.17.0

Anaconda

下载

wget https://repo.anaconda.com/archive/Anaconda3-2023.03-Linux-x86_64.sh
bash Anaconda3-2023.03-Linux-x86_64.sh
# 之后根据提示输入

jupyter-lab

安装完Anaconda默认就自带jupyter了

  1. 生成配置文件
jupyter lab --generate-config
  1. 设置密码
jupyter lab password
  1. 自动闭合(括号、引号这些)
    启动jupyter-lab后,在页面上方settings中找到Auto Close Brackets打勾

  2. 常用启动参数

# 指定IP
jupyter-lab --ip 0.0.0.0 
# 指定端口
jupyter-lab --port 8888
# 不自动启动浏览器
jupyter-lab --no-browser
插件安装
  1. 启动jupyter-lab后,打开Extension Manager ,点击enable启动插件
  2. 查看已安装的插件
jupyter server extension list
  1. 自动代码提示插件(需要node环境)
    首先
pip install jupyterlab-lsp
pip install 'python-lsp-server[all]'

然后在JupyterLab中的Extension Manager中找到jupyterlab-lsp点击install,经过漫长的等待,它可能会让你重启jupyter-lab
如果失败了可以用jupyter server extension list查看jupyterlab-lsp是否安装成功

  1. 启用或关闭插件(未测试)
# 关闭估计就是把`enable`改为`disable`
jupyter server extension enable --user --py jupyter_lsp

Pyenv

安装

curl https://pyenv.run | bash

配置环境

编辑~/.zprofile~/.zshrc,添加

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

~/.zshrc添加

eval "$(pyenv virtualenv-init -)"

修改镜像源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
安装指定版本python
pyenv install 3.8.16
设置默认python环境
pyenv global 3.8.16
删除python环境
pyenv uninstall 3.8.16
创建虚拟环境
pyenv virtualenv 3.8.16 my_env
查看虚拟环境
pyenv virtualenvs
激活虚拟环境
pyenv activate my_env

frp 内网穿透

地址: https://github.com/fatedier/frp
下载: https://github.com/fatedier/frp/releases

wget https://github.com/fatedier/frp/releases/download/v0.48.0/frp_0.48.0_linux_amd64.tar.gz
tar -zxvf frp_0.48.0_linux_amd64.tar.gz
cd frp_0.48.0_linux_amd64
sudo cp frpc /usr/bin/frpc
sudo cp frps /usr/bin/frps

客户端配置

  1. 创建文件夹/etc/frp/
  2. 创建文件sudo vim /etc/frp/frpc.ini
[common]
server_addr = 你的服务端IP
server_port = 你的服务端端口
token = 连接密码 

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 22022
  1. 创建开机自启动服务
    创建文件/lib/systemd/system/frpc.service
[Unit]
Description=Frp Client Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/frpc -c /etc/frp/frpc.ini
ExecReload=/usr/bin/frpc reload -c /etc/frp/frpc.ini
LimitNOFILE=1048576

[Install]
WantedBy=multi-user.target

  1. 配置开机启动
systemctl enable --now frpc.service

grub(双系统)

在先装windows后装ubuntu的情况下,执行下面的命令会自动识别windows引导项

sudo update-grub2

配置主题

下载主题

挑一个好看的主题下载,地址:https://www.gnome-look.org/browse?cat=109&ord=latest
我下载的是Distro

sudo mkdir -p /boot/grub/themes/distro
sudo tar -xvf ubuntu.tar -C /boot/grub/themes/distro/
修改配置文件

编辑/etc/default/grub
插入下面内容

GRUB_THEME="/boot/grub/themes/distro/theme.txt"

注释GRUB_TIMEOUT_STYLE=hidden
更新配置

sudo update-grub 

落雪音乐

地址:https://github.com/lyswhut/lx-music-desktop

sudo dpkg -i lx-music-desktop-v2.2.0-x64.deb 

下面的用到再写

docker

vscode

vlc

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值