sudo go找不到命令
时间: 2023-11-27 12:03:53 浏览: 33
这个问题可能是因为您的系统中没有安装 Go 编程语言或者 Go 的可执行文件路径没有被添加到系统环境变量中。您可以尝试使用以下命令安装 Go:
```
sudo apt-get update
sudo apt-get install golang
```
如果已经安装了 Go,您可以尝试将 Go 的可执行文件路径添加到系统环境变量中。您可以在终端中执行以下命令:
```
export PATH=$PATH:/usr/local/go/bin
```
相关问题
golang 实现不联网安装nginx
可以通过以下步骤在不联网的情况下安装Nginx:
1. 从其他联网的机器上下载Nginx的源码包(tar.gz格式)并复制到目标机器上。
2. 解压源码包,进入Nginx目录。
```sh
tar -xzvf nginx-x.x.x.tar.gz
cd nginx-x.x.x
```
3. 安装编译Nginx所需的依赖库。
```sh
sudo apt-get update
sudo apt-get install build-essential libpcre3 libpcre3-dev zlib1g-dev libssl-dev
```
4. 配置Nginx。
```sh
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module
```
这里指定了安装目录为`/usr/local/nginx`,同时开启了SSL、状态页和gzip静态压缩功能。
5. 编译并安装Nginx。
```sh
make
sudo make install
```
6. 验证Nginx是否安装成功。
```sh
/usr/local/nginx/sbin/nginx -v
```
如果显示Nginx版本号,则说明安装成功。
7. 配置Nginx服务启动脚本。
```sh
sudo nano /etc/init.d/nginx
```
将以下内容复制到文件中:
```sh
#!/bin/bash
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
```
然后执行以下命令保存并退出。
```
Ctrl+X
Y
Enter
```
8. 授予脚本执行权限。
```sh
sudo chmod +x /etc/init.d/nginx
```
9. 启动Nginx服务。
```sh
sudo service nginx start
```
验证Nginx是否已经启动:
```sh
ps aux | grep nginx
```
如果看到类似以下输出,则说明Nginx已经成功启动。
```sh
root 1234 0.0 0.2 12345 6789 ? Ss 12:34 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx 5678 0.0 0.5 23456 9876 ? S 12:35 0:00 nginx: worker process
nginx 5679 0.0 0.5 23456 9876 ? S 12:35 0:00 nginx: worker process
```
现在,您已经成功在不联网的情况下安装了Nginx。
怎么将写的go代码移植到linux系统arm架构中使用
要将编写的Go代码移植到Linux系统的ARM架构中使用,需要进行以下步骤:
1. 安装ARM架构的交叉编译工具链。可以使用命令`sudo apt-get install gcc-arm-linux-gnueabihf`进行安装。
2. 在Go代码的根目录下创建一个名为`cross_compile.sh`的脚本文件,并将以下内容复制到该文件中:
```
#!/bin/bash
export GOARCH=arm
export GOOS=linux
export CGO_ENABLED=0
export CC=arm-linux-gnueabihf-gcc
go build -a -tags netgo -ldflags '-w -extldflags "-static"' .
```
3. 运行该脚本文件,编译出ARM架构的可执行文件。
4. 将生成的可执行文件上传到ARM架构的Linux系统上,并赋予执行权限。
5. 在ARM架构的Linux系统上运行该可执行文件即可。
注意:在编译过程中,需要添加`-tags netgo`和`-ldflags '-w -extldflags "-static"'`参数,以确保编译出来的可执行文件不依赖于系统库。