1. 程式人生 > 實用技巧 >Linux安裝redis報錯:jemalloc/jemalloc.h: No such file or directory踩坑

Linux安裝redis報錯:jemalloc/jemalloc.h: No such file or directory踩坑

報錯內容:

針對這個錯誤,我們可以在README.md 檔案中看到解釋:

---------

Selecting a non-default memory allocator when building Redis is done by setting
the `MALLOC` environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.

To force compiling against libc malloc, use:

    % make MALLOC=libc

To compile against jemalloc on Mac OS X systems, use:

    % make MALLOC=jemalloc

Verbose build
-------------

  網上大部分解決辦法都是錯誤的,如下文:

make MALLOC=libc

  正確解決辦法(針對2.2以上的版本)
清理上次編譯殘留檔案,重新編譯:

make distclean  && make

錯誤的本質是我們在開始執行make 時遇到了錯誤(大部分是由於gcc未安裝),然後我們安裝好了gcc 後,我們再執行make ,這時就出現了jemalloc/jemalloc.h: No such file or directory。這是因為上次的

編譯失敗,有殘留的檔案,我們需要清理下,然後重新編譯就可以了。

網上的解決辦法雖然最後也是可以成功安裝好 redis ,但是是有一些隱患的,首先我們要知道redis 需要使用記憶體分配器的, make MALLOC=jemalloc 就是指定記憶體分配器為 jemalloc ,make MALLOC=libc 就是指定記憶體分配器為 libc ,這個是有安全隱患的,jemalloc 記憶體分配器在實踐中處理記憶體碎片是要比libc 好的,而且在README.md 文件也說明到了,jemalloc記憶體分配器也是包含在原始碼包裡面的,可以在deps 目錄下看到 jemalloc 目錄。